fixed a memory leak, improved error handling in cache system

This commit is contained in:
Fufu Fang 2024-05-03 07:19:24 +01:00
parent d4c7d8c92a
commit a299819b7d
No known key found for this signature in database
GPG Key ID: 8A4CB08B0A7E27CE
1 changed files with 9 additions and 3 deletions

View File

@ -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;