[PATCH] hw/core/loader: gunzip(): fix memory leak on error path

Vladimir Sementsov-Ogievskiy posted 1 patch 5 months ago
Patches applied successfully (tree, apply log)
git fetch https://github.com/patchew-project/qemu tags/patchew/20240627162507.598352-1-vsementsov@yandex-team.ru
hw/core/loader.c | 1 +
1 file changed, 1 insertion(+)
[PATCH] hw/core/loader: gunzip(): fix memory leak on error path
Posted by Vladimir Sementsov-Ogievskiy 5 months ago
We should call inflateEnd() like on success path to cleanup state in s
variable.

Signed-off-by: Vladimir Sementsov-Ogievskiy <vsementsov@yandex-team.ru>
---
 hw/core/loader.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/hw/core/loader.c b/hw/core/loader.c
index 2f8105d7de..a3bea1e718 100644
--- a/hw/core/loader.c
+++ b/hw/core/loader.c
@@ -610,6 +610,7 @@ ssize_t gunzip(void *dst, size_t dstlen, uint8_t *src, size_t srclen)
     r = inflate(&s, Z_FINISH);
     if (r != Z_OK && r != Z_STREAM_END) {
         printf ("Error: inflate() returned %d\n", r);
+        inflateEnd(&s);
         return -1;
     }
     dstbytes = s.next_out - (unsigned char *) dst;
-- 
2.34.1
Re: [PATCH] hw/core/loader: gunzip(): fix memory leak on error path
Posted by Philippe Mathieu-Daudé 4 months, 3 weeks ago
On 27/6/24 18:25, Vladimir Sementsov-Ogievskiy wrote:
> We should call inflateEnd() like on success path to cleanup state in s
> variable.
> 
> Signed-off-by: Vladimir Sementsov-Ogievskiy <vsementsov@yandex-team.ru>
> ---
>   hw/core/loader.c | 1 +
>   1 file changed, 1 insertion(+)

Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org>