atrace: Fix a possible leak 65/318665/2
authorSung-hun Kim <sfoon.kim@samsung.com>
Wed, 22 Jan 2025 02:34:58 +0000 (11:34 +0900)
committerSung-hun Kim <sfoon.kim@samsung.com>
Wed, 22 Jan 2025 05:46:50 +0000 (14:46 +0900)
zlib's inflateInit() allocated some resourced to maintain the deflate process.
So, if should be released before the exit (coverity issue number: 1830902).

Change-Id: Ie09037f2ebce1b1dbc5ba28037151b19025dd722
Signed-off-by: Sung-hun Kim <sfoon.kim@samsung.com>
atrace/atrace.cpp

index 4d068452fb8ad5224eeb1e78ccea3c30263a7761..92ef1e941d231c57ad7f7d59d55552a583eb8909 100755 (executable)
@@ -760,7 +760,10 @@ static void dumpTrace(bool startup)
         std::unique_ptr<uint8_t[]> in(new(std::nothrow) uint8_t[bufSize]);
         std::unique_ptr<uint8_t[]> out(new(std::nothrow) uint8_t[bufSize]);
         if ((in == nullptr) || (out == nullptr)) {
-            fprintf(stderr, "Could not allocate memory");
+            fprintf(stderr, "Could not allocate memory\n");
+            result = deflateEnd(&zs);
+            if (result != Z_OK)
+               fprintf(stderr, "error cleaning up zlib: %d\n", result);
             close(traceFD);
             if (backup_fd > -1)
                 close(backup_fd);