Skip to content

Commit

Permalink
fix: realloc identical to free when size = 0
Browse files Browse the repository at this point in the history
  • Loading branch information
XuJiandong committed Jan 16, 2025
1 parent ff132f7 commit 9c7e9c9
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions libc/src/malloc.c
Original file line number Diff line number Diff line change
Expand Up @@ -300,6 +300,10 @@ void *realloc(void *p, size_t n) {
void *new;

if (!p) return malloc(n);
if (p && (n == 0)) {
free(p);
return 0;
}

if (adjust_size(&n) < 0) return 0;

Expand Down

0 comments on commit 9c7e9c9

Please sign in to comment.