From a299819b7d7d34a2c94531b835b02b26f32ff12b Mon Sep 17 00:00:00 2001 From: Fufu Fang Date: Fri, 3 May 2024 07:19:24 +0100 Subject: [PATCH] fixed a memory leak, improved error handling in cache system --- src/cache.c | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/src/cache.c b/src/cache.c index 254faae..05fe020 100644 --- a/src/cache.c +++ b/src/cache.c @@ -549,15 +549,15 @@ static int Cache_exist(const char *fn) int no_data = access(datafn, F_OK); if (no_meta ^ no_data) { + lprintf(warning, "Cache file partially missing.\n"); if (no_meta) { - lprintf(warning, "Cache file partially missing.\n"); if (unlink(datafn)) { - lprintf(error, "unlink(): %s\n", strerror(errno)); + lprintf(fatal, "unlink(): %s\n", strerror(errno)); } } if (no_data) { if (unlink(metafn)) { - lprintf(error, "unlink(): %s\n", strerror(errno)); + lprintf(fatal, "unlink(): %s\n", strerror(errno)); } } } @@ -710,8 +710,14 @@ int Cache_create(const char *path) int res = Cache_exist(fn); + if (res) { + lprintf(fatal, "Cache file creation failed for %s\n", path); + } + if (CONFIG.mode == NORMAL) { curl_free(fn); + } else if (CONFIG.mode == SONIC) { + curl_free(fn); } return res;