From 6711d10f96e0862f7b0b086d3a35358787b6d552 Mon Sep 17 00:00:00 2001 From: Allan McRae Date: Sat, 27 Jan 2024 00:28:03 +1000 Subject: [PATCH] pacman/conf.c: fix leak on error in setdefaults() Signed-off-by: Allan McRae --- src/pacman/conf.c | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/src/pacman/conf.c b/src/pacman/conf.c index 8396d02d..14096441 100644 --- a/src/pacman/conf.c +++ b/src/pacman/conf.c @@ -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 {