[pacman-dev] [PATCH] initialize pointers passed to _alpm_pkg_dup
_alpm_pkg_dup leaves the destination pointer unaltered in case of fatal errors, so when commits 2f0ca00e and be4198b3 freed the pointer, they fixed a memory leak on non-fatal errors by replacing it with a segmentation fault on fatal errors. Signed-off-by: Andrew Gregory <andrew.gregory.8@gmail.com> --- lib/libalpm/db.c | 2 +- lib/libalpm/deps.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/libalpm/db.c b/lib/libalpm/db.c index bfc80ac..ebcd1f8 100644 --- a/lib/libalpm/db.c +++ b/lib/libalpm/db.c @@ -565,7 +565,7 @@ alpm_list_t *_alpm_db_get_pkgcache(alpm_db_t *db) /* "duplicate" pkg then add it to pkgcache */ int _alpm_db_add_pkgincache(alpm_db_t *db, alpm_pkg_t *pkg) { - alpm_pkg_t *newpkg; + alpm_pkg_t *newpkg = NULL; if(db == NULL || pkg == NULL || !(db->status & DB_STATUS_PKGCACHE)) { return -1; diff --git a/lib/libalpm/deps.c b/lib/libalpm/deps.c index d4fbf95..c340f11 100644 --- a/lib/libalpm/deps.c +++ b/lib/libalpm/deps.c @@ -609,7 +609,7 @@ int _alpm_recursedeps(alpm_db_t *db, alpm_list_t **targs, int include_explicit) alpm_pkg_t *deppkg = j->data; if(_alpm_pkg_depends_on(pkg, deppkg) && can_remove_package(db, deppkg, *targs, include_explicit)) { - alpm_pkg_t *copy; + alpm_pkg_t *copy = NULL; _alpm_log(db->handle, ALPM_LOG_DEBUG, "adding '%s' to the targets\n", deppkg->name); /* add it to the target list */ -- 2.2.1
On 02/01/15 10:00, Andrew Gregory wrote:
_alpm_pkg_dup leaves the destination pointer unaltered in case of fatal errors, so when commits 2f0ca00e and be4198b3 freed the pointer, they fixed a memory leak on non-fatal errors by replacing it with a segmentation fault on fatal errors.
Signed-off-by: Andrew Gregory <andrew.gregory.8@gmail.com> --- lib/libalpm/db.c | 2 +- lib/libalpm/deps.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-)
diff --git a/lib/libalpm/db.c b/lib/libalpm/db.c index bfc80ac..ebcd1f8 100644 --- a/lib/libalpm/db.c +++ b/lib/libalpm/db.c @@ -565,7 +565,7 @@ alpm_list_t *_alpm_db_get_pkgcache(alpm_db_t *db) /* "duplicate" pkg then add it to pkgcache */ int _alpm_db_add_pkgincache(alpm_db_t *db, alpm_pkg_t *pkg) { - alpm_pkg_t *newpkg; + alpm_pkg_t *newpkg = NULL;
That is created using CALLOC.
if(db == NULL || pkg == NULL || !(db->status & DB_STATUS_PKGCACHE)) { return -1; diff --git a/lib/libalpm/deps.c b/lib/libalpm/deps.c index d4fbf95..c340f11 100644 --- a/lib/libalpm/deps.c +++ b/lib/libalpm/deps.c @@ -609,7 +609,7 @@ int _alpm_recursedeps(alpm_db_t *db, alpm_list_t **targs, int include_explicit) alpm_pkg_t *deppkg = j->data; if(_alpm_pkg_depends_on(pkg, deppkg) && can_remove_package(db, deppkg, *targs, include_explicit)) { - alpm_pkg_t *copy; + alpm_pkg_t *copy = NULL;'
This is not in _alpm_pkg_dup...
_alpm_log(db->handle, ALPM_LOG_DEBUG, "adding '%s' to the targets\n", deppkg->name); /* add it to the target list */
On 02/01/15 11:46, Allan McRae wrote:
On 02/01/15 10:00, Andrew Gregory wrote:
_alpm_pkg_dup leaves the destination pointer unaltered in case of fatal errors, so when commits 2f0ca00e and be4198b3 freed the pointer, they fixed a memory leak on non-fatal errors by replacing it with a segmentation fault on fatal errors.
Patch has been explained to me. Ack.
participants (2)
-
Allan McRae
-
Andrew Gregory