[pacman-dev] [PATCH] Fixed a memory leak when unresolved packages are removed from transaction
bji-keyword-pacman.3644cb at www.ischo.com
bji-keyword-pacman.3644cb at www.ischo.com
Fri Mar 6 23:10:15 EST 2009
From: Bryan Ischo <bji-keyword-pacman.3644cb at www.ischo.com>
Signed-off-by: Bryan Ischo <bji-keyword-pacman.3644cb at www.ischo.com>
---
lib/libalpm/sync.c | 21 ++++++++++++++++++++-
1 files changed, 20 insertions(+), 1 deletions(-)
diff --git a/lib/libalpm/sync.c b/lib/libalpm/sync.c
index fca96d8..fe4eded 100644
--- a/lib/libalpm/sync.c
+++ b/lib/libalpm/sync.c
@@ -431,7 +431,10 @@ int _alpm_sync_prepare(pmtrans_t *trans, pmdb_t *db_local, alpm_list_t *dbs_sync
}
/* Resolve packages in the transaction one at a time, in addtion
- building up a list of packages which could not be resolved. */
+ building up a list of packages which could not be resolved.
+ The list which is created by this loop is used later to replace
+ trans->packages; the unresolvable packages which were in the old
+ trans->packages list but not in the new list are freed up later. */
for(i = trans->packages; i; i = i->next) {
pmpkg_t *pkg = ((pmsyncpkg_t *) i->data)->pkg;
if(_alpm_resolvedeps(db_local, dbs_sync, pkg, &list, remove, data) == -1) {
@@ -500,6 +503,22 @@ int _alpm_sync_prepare(pmtrans_t *trans, pmdb_t *db_local, alpm_list_t *dbs_sync
}
}
alpm_list_free(sortlist);
+
+ /* Destroy all packages which are in trans->packages but not in
+ newpkgs before replacing trans->packages with newpkgs */
+ for(i = trans->packages; i; i = i->next) {
+ pmsyncpkg_t *spkg = (pmsyncpkg_t *) i->data;
+ for (j = newpkgs; j; j = j->next) {
+ if(_alpm_pkg_cmp(spkg->pkg, ((pmsyncpkg_t *) j->data)->pkg) == 0) {
+ spkg = NULL;
+ break;
+ }
+ }
+ if (spkg != NULL) {
+ _alpm_sync_free(spkg);
+ }
+ }
+
alpm_list_free(trans->packages);
trans->packages = newpkgs;
--
1.6.1.3
More information about the pacman-dev
mailing list