From: Jonathan Dieter Date: Tue, 4 Apr 2023 20:14:49 +0000 (+0100) Subject: Ensure memory is freed when zrealloc is called with size 0 X-Git-Tag: archive/raspbian/1.3.1+ds1-1+rpi1^2~5^2~1 X-Git-Url: https://dgit.raspbian.org/?a=commitdiff_plain;h=38ef83d846c25a24fe01655b1f2b5ca91c94f997;p=zchunk.git Ensure memory is freed when zrealloc is called with size 0 zrealloc is supposed to handle freeing the old pointer when called, but when called with size 0, it was not always working as expected. This commit fixes the bug. Thanks to Agostino Sarubbo of Gentoo for providing a bug report with a reproducible test case. Signed-off-by: Jonathan Dieter --- diff --git a/src/lib/zck.c b/src/lib/zck.c index 8593281..0f5fc52 100644 --- a/src/lib/zck.c +++ b/src/lib/zck.c @@ -134,6 +134,13 @@ void *zmalloc(size_t size) { } void *zrealloc(void *ptr, size_t size) { + /* Handle requested size of zero */ + if(size == 0) { + if(ptr != NULL) + free(ptr); + return NULL; + } + void *ret = realloc(ptr, size); /* * Realloc does not touch the original block if fails.