From 02162731c1899613bce2aafc825acc7baa3cc99a Mon Sep 17 00:00:00 2001 From: Samanta Navarro Date: Sun, 8 Nov 2020 11:44:55 +0000 Subject: [PATCH] libblkid: fix memory leak in config parser Multiple occurrences of CACHE_FILE lead to memory leaks. Also if last occurrence of CACHE_FILE is empty then cache file is not set to NULL again. An example /etc/blkid.conf could be: CACHE_FILE=/tmp/cache1 CACHE_FILE=/tmp/cache2 CACHE_FILE= I would expect that CACHE_FILE is empty but actually it is still /tmp/cache2. Signed-off-by: Samanta Navarro --- libblkid/src/config.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/libblkid/src/config.c b/libblkid/src/config.c index 52f159d870..f229b3e632 100644 --- a/libblkid/src/config.c +++ b/libblkid/src/config.c @@ -95,8 +95,11 @@ static int parse_next(FILE *fd, struct blkid_config *conf) conf->uevent = FALSE; } else if (!strncmp(s, "CACHE_FILE=", 11)) { s += 11; + free(conf->cachefile); if (*s) conf->cachefile = strdup(s); + else + conf->cachefile = NULL; } else if (!strncmp(s, "EVALUATE=", 9)) { s += 9; if (*s && parse_evaluate(conf, s) == -1) -- 2.47.3