pacman/conf.c: fix leak on error in setdefaults()

Signed-off-by: Allan McRae <allan@archlinux.org>
This commit is contained in:
Allan McRae 2024-01-27 00:28:03 +10:00
parent 36fcff6e13
commit 6711d10f96

View file

@ -1164,12 +1164,24 @@ int setdefaults(config_t *c)
}
char path[PATH_MAX];
if(!c->dbpath) {
char* ppath;
snprintf(path, PATH_MAX, "%s/%s", rootdir, &DBPATH[1]);
SETDEFAULT(c->dbpath, strdup(path));
ppath = strdup(path);
if(ppath == NULL) {
free(rootdir);
return -1;
}
SETDEFAULT(c->dbpath, ppath);
}
if(!c->logfile) {
char* ppath;
snprintf(path, PATH_MAX, "%s/%s", rootdir, &LOGFILE[1]);
SETDEFAULT(c->logfile, strdup(path));
ppath = strdup(path);
if(ppath == NULL) {
free(rootdir);
return -1;
}
SETDEFAULT(c->logfile, ppath);
}
free(rootdir);
} else {