posix: fix direct use of `malloc` In "posix.c" there are multiple callsites which execute `malloc` instead of `git__malloc`. Thus, users of library are not able to track these allocations with a custom allocator. Convert these call sites to use `git__malloc` instead.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54
diff --git a/src/posix.c b/src/posix.c
index bffe02e..1ea2ce5 100644
--- a/src/posix.c
+++ b/src/posix.c
@@ -28,11 +28,11 @@ int p_getaddrinfo(
GIT_UNUSED(hints);
- if ((ainfo = malloc(sizeof(struct addrinfo))) == NULL)
+ if ((ainfo = git__malloc(sizeof(struct addrinfo))) == NULL)
return -1;
if ((ainfo->ai_hostent = gethostbyname(host)) == NULL) {
- free(ainfo);
+ git__free(ainfo);
return -2;
}
@@ -65,7 +65,7 @@ int p_getaddrinfo(
ai = ainfo;
for (p = 1; ainfo->ai_hostent->h_addr_list[p] != NULL; p++) {
- if (!(ai->ai_next = malloc(sizeof(struct addrinfo)))) {
+ if (!(ai->ai_next = git__malloc(sizeof(struct addrinfo)))) {
p_freeaddrinfo(ainfo);
return -1;
}
@@ -89,7 +89,7 @@ void p_freeaddrinfo(struct addrinfo *info)
while(p != NULL) {
next = p->ai_next;
- free(p);
+ git__free(p);
p = next;
}
}
@@ -247,7 +247,7 @@ int p_mmap(git_map *out, size_t len, int prot, int flags, int fd, git_off_t offs
return -1;
}
- out->data = malloc(len);
+ out->data = git__malloc(len);
GIT_ERROR_CHECK_ALLOC(out->data);
if (!git__is_ssizet(len) ||
@@ -264,7 +264,7 @@ int p_mmap(git_map *out, size_t len, int prot, int flags, int fd, git_off_t offs
int p_munmap(git_map *map)
{
assert(map != NULL);
- free(map->data);
+ git__free(map->data);
return 0;
}