Skip to content

Commit

Permalink
realloc(): fix possible memory leak
Browse files Browse the repository at this point in the history
If size is equal to zero, and ptr is not NULL, then the call must be
equivalent to free(ptr).

Signed-off-by: Nicolas Pitre <npitre@baylibre.com>
  • Loading branch information
Nicolas Pitre authored and andrewboie committed Jul 12, 2019
1 parent 92ddf63 commit ff7e4e6
Showing 1 changed file with 1 addition and 0 deletions.
1 change: 1 addition & 0 deletions lib/libc/minimal/source/stdlib/malloc.c
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ void *realloc(void *ptr, size_t requested_size)
}

if (requested_size == 0) {
free(ptr);
return NULL;
}

Expand Down

0 comments on commit ff7e4e6

Please sign in to comment.