Skip to content

Commit 8c7d976

Browse files
committed
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 parent a477bff commit 8c7d976

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

src/posix.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,11 @@ int p_getaddrinfo(
2828

2929
GIT_UNUSED(hints);
3030

31-
if ((ainfo = malloc(sizeof(struct addrinfo))) == NULL)
31+
if ((ainfo = git__malloc(sizeof(struct addrinfo))) == NULL)
3232
return -1;
3333

3434
if ((ainfo->ai_hostent = gethostbyname(host)) == NULL) {
35-
free(ainfo);
35+
git__free(ainfo);
3636
return -2;
3737
}
3838

@@ -65,7 +65,7 @@ int p_getaddrinfo(
6565
ai = ainfo;
6666

6767
for (p = 1; ainfo->ai_hostent->h_addr_list[p] != NULL; p++) {
68-
if (!(ai->ai_next = malloc(sizeof(struct addrinfo)))) {
68+
if (!(ai->ai_next = git__malloc(sizeof(struct addrinfo)))) {
6969
p_freeaddrinfo(ainfo);
7070
return -1;
7171
}
@@ -89,7 +89,7 @@ void p_freeaddrinfo(struct addrinfo *info)
8989

9090
while(p != NULL) {
9191
next = p->ai_next;
92-
free(p);
92+
git__free(p);
9393
p = next;
9494
}
9595
}
@@ -247,7 +247,7 @@ int p_mmap(git_map *out, size_t len, int prot, int flags, int fd, git_off_t offs
247247
return -1;
248248
}
249249

250-
out->data = malloc(len);
250+
out->data = git__malloc(len);
251251
GIT_ERROR_CHECK_ALLOC(out->data);
252252

253253
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
264264
int p_munmap(git_map *map)
265265
{
266266
assert(map != NULL);
267-
free(map->data);
267+
git__free(map->data);
268268

269269
return 0;
270270
}

0 commit comments

Comments
 (0)