From dfe1c4bc742ed3f53c06bb232ebc1f5fadd0881e Mon Sep 17 00:00:00 2001 From: Karel Zak Date: Mon, 13 Jan 2025 11:26:06 +0100 Subject: [PATCH] libblkid: fix potential memory leaks Addresses: https://github.com/util-linux/util-linux/pull/3356 Signed-off-by: Karel Zak --- libblkid/src/save.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/libblkid/src/save.c b/libblkid/src/save.c index 1a617c072e..295924e15a 100644 --- a/libblkid/src/save.c +++ b/libblkid/src/save.c @@ -109,7 +109,8 @@ int blkid_flush_cache(blkid_cache cache) && errno != EEXIST) { DBG(SAVE, ul_debug("can't create %s directory for cache file", BLKID_RUNTIME_DIR)); - return 0; + ret = 0; + goto done; } } @@ -117,7 +118,8 @@ int blkid_flush_cache(blkid_cache cache) if (((ret = stat(filename, &st)) < 0 && errno != ENOENT) || (ret == 0 && access(filename, W_OK) < 0)) { DBG(SAVE, ul_debug("can't write to cache file %s", filename)); - return 0; + ret = 0; + goto done; } /* @@ -154,7 +156,7 @@ int blkid_flush_cache(blkid_cache cache) if (!file) { ret = errno; - goto errout; + goto done; } list_for_each(p, &cache->bic_devs) { @@ -201,7 +203,7 @@ int blkid_flush_cache(blkid_cache cache) } } -errout: +done: free(tmp); if (filename != cache->bic_filename) free(filename); -- 2.47.3