[pacman-dev] [PATCH 1/4] pacman.c: Remove redundant strdup() in parsearg_global()
config_set_arch() already calls strdup(). Remove strdup() from the config_set_arch() invocation to avoid a memory leak. Signed-off-by: Lukas Fleischer <archlinux@cryptocrack.de> --- src/pacman/pacman.c | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-) diff --git a/src/pacman/pacman.c b/src/pacman/pacman.c index 71413bd..d285a05 100644 --- a/src/pacman/pacman.c +++ b/src/pacman/pacman.c @@ -385,7 +385,7 @@ static int parsearg_global(int opt) switch(opt) { case OP_ARCH: check_optarg(); - config_set_arch(strdup(optarg)); + config_set_arch(optarg); break; case OP_ASK: check_optarg(); -- 1.7.6.1
Jump to the cleanup label, free "pkgpath" and restore umask if a non-local database is passed. Signed-off-by: Lukas Fleischer <archlinux@cryptocrack.de> --- lib/libalpm/be_local.c | 3 ++- 1 files changed, 2 insertions(+), 1 deletions(-) diff --git a/lib/libalpm/be_local.c b/lib/libalpm/be_local.c index f53bd64..4844ade 100644 --- a/lib/libalpm/be_local.c +++ b/lib/libalpm/be_local.c @@ -760,7 +760,8 @@ int _alpm_local_db_write(alpm_db_t *db, alpm_pkg_t *info, alpm_dbinfrq_t inforeq oldmask = umask(0022); if(strcmp(db->treename, "local") != 0) { - return -1; + retval = -1; + goto cleanup; } /* DESC */ -- 1.7.6.1
On Fri, Aug 26, 2011 at 6:10 AM, Lukas Fleischer <archlinux@cryptocrack.de> wrote:
Jump to the cleanup label, free "pkgpath" and restore umask if a non-local database is passed.
Signed-off-by: Lukas Fleischer <archlinux@cryptocrack.de>
This seemed like the better solution, but thanks for pointing out the problem: diff --git a/lib/libalpm/be_local.c b/lib/libalpm/be_local.c index f53bd64..1a46dfd 100644 --- a/lib/libalpm/be_local.c +++ b/lib/libalpm/be_local.c @@ -750,7 +750,7 @@ int _alpm_local_db_write(alpm_db_t *db, alpm_pkg_t *info, alpm_dbinfrq_t inforeq int retval = 0; char *pkgpath = NULL; - if(db == NULL || info == NULL) { + if(db == NULL || info == NULL || !(db->status & DB_STATUS_LOCAL)) { return -1; } @@ -759,10 +759,6 @@ int _alpm_local_db_write(alpm_db_t *db, alpm_pkg_t *info, alpm_dbinfrq_t inforeq /* make sure we have a sane umask */ oldmask = umask(0022); - if(strcmp(db->treename, "local") != 0) { - return -1; - } - /* DESC */ if(inforeq & INFRQ_DESC) { _alpm_log(db->handle, ALPM_LOG_DEBUG, "writing %s-%s DESC information back to db\n",
Free "syncpath" and restore umask if we fail to grab a lock. Signed-off-by: Lukas Fleischer <archlinux@cryptocrack.de> --- lib/libalpm/be_sync.c | 2 ++ 1 files changed, 2 insertions(+), 0 deletions(-) diff --git a/lib/libalpm/be_sync.c b/lib/libalpm/be_sync.c index 6e64e5f..5e53798 100644 --- a/lib/libalpm/be_sync.c +++ b/lib/libalpm/be_sync.c @@ -176,6 +176,8 @@ int SYMEXPORT alpm_db_update(int force, alpm_db_t *db) /* attempt to grab a lock */ if(_alpm_handle_lock(handle)) { + free(syncpath); + umask(oldmask); RET_ERR(handle, ALPM_ERR_HANDLE_LOCK, -1); } -- 1.7.6.1
On Fri, Aug 26, 2011 at 6:10 AM, Lukas Fleischer <archlinux@cryptocrack.de> wrote:
Free "syncpath" and restore umask if we fail to grab a lock.
Signed-off-by: Lukas Fleischer <archlinux@cryptocrack.de> Thanks. --- lib/libalpm/be_sync.c | 2 ++ 1 files changed, 2 insertions(+), 0 deletions(-)
diff --git a/lib/libalpm/be_sync.c b/lib/libalpm/be_sync.c index 6e64e5f..5e53798 100644 --- a/lib/libalpm/be_sync.c +++ b/lib/libalpm/be_sync.c @@ -176,6 +176,8 @@ int SYMEXPORT alpm_db_update(int force, alpm_db_t *db)
/* attempt to grab a lock */ if(_alpm_handle_lock(handle)) { + free(syncpath); + umask(oldmask); RET_ERR(handle, ALPM_ERR_HANDLE_LOCK, -1); }
-- 1.7.6.1
Free "md5sum" if md5_file() fails in alpm_compute_md5sum(). Free "sha256sum" if sha2_file() fails in alpm_compute_sha256sum(). Signed-off-by: Lukas Fleischer <archlinux@cryptocrack.de> --- lib/libalpm/util.c | 2 ++ 1 files changed, 2 insertions(+), 0 deletions(-) diff --git a/lib/libalpm/util.c b/lib/libalpm/util.c index 7e3bc37..3d1f9d5 100644 --- a/lib/libalpm/util.c +++ b/lib/libalpm/util.c @@ -831,6 +831,7 @@ char SYMEXPORT *alpm_compute_md5sum(const char *filename) ret = md5_file(filename, output); if(ret > 0) { + free(md5sum); return NULL; } @@ -862,6 +863,7 @@ char SYMEXPORT *alpm_compute_sha256sum(const char *filename) ret = sha2_file(filename, output, 0); if(ret > 0) { + free(sha256sum); return NULL; } -- 1.7.6.1
On Fri, Aug 26, 2011 at 6:10 AM, Lukas Fleischer <archlinux@cryptocrack.de> wrote:
Free "md5sum" if md5_file() fails in alpm_compute_md5sum(). Free "sha256sum" if sha2_file() fails in alpm_compute_sha256sum().
Signed-off-by: Lukas Fleischer <archlinux@cryptocrack.de> Thanks. --- lib/libalpm/util.c | 2 ++ 1 files changed, 2 insertions(+), 0 deletions(-)
diff --git a/lib/libalpm/util.c b/lib/libalpm/util.c index 7e3bc37..3d1f9d5 100644 --- a/lib/libalpm/util.c +++ b/lib/libalpm/util.c @@ -831,6 +831,7 @@ char SYMEXPORT *alpm_compute_md5sum(const char *filename) ret = md5_file(filename, output);
if(ret > 0) { + free(md5sum); return NULL; }
@@ -862,6 +863,7 @@ char SYMEXPORT *alpm_compute_sha256sum(const char *filename) ret = sha2_file(filename, output, 0);
if(ret > 0) { + free(sha256sum); return NULL; }
-- 1.7.6.1
On Fri, Aug 26, 2011 at 6:10 AM, Lukas Fleischer <archlinux@cryptocrack.de> wrote:
config_set_arch() already calls strdup(). Remove strdup() from the config_set_arch() invocation to avoid a memory leak.
Signed-off-by: Lukas Fleischer <archlinux@cryptocrack.de> Thanks. --- src/pacman/pacman.c | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-)
diff --git a/src/pacman/pacman.c b/src/pacman/pacman.c index 71413bd..d285a05 100644 --- a/src/pacman/pacman.c +++ b/src/pacman/pacman.c @@ -385,7 +385,7 @@ static int parsearg_global(int opt) switch(opt) { case OP_ARCH: check_optarg(); - config_set_arch(strdup(optarg)); + config_set_arch(optarg); break; case OP_ASK: check_optarg(); -- 1.7.6.1
participants (2)
-
Dan McGee
-
Lukas Fleischer