From 0f834c93c7d33af8a828fc3753f46e92a868554f Mon Sep 17 00:00:00 2001 From: Xavier Chantry Date: Sat, 19 Sep 2009 03:00:13 +0200 Subject: testdb : fix many memleaks Yes, it was that bad :P We still have memleaks left because we cannot free the error data returned by libalpm, but pacman has the same issue. Signed-off-by: Xavier Chantry Signed-off-by: Dan McGee --- src/util/testdb.c | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) (limited to 'src') diff --git a/src/util/testdb.c b/src/util/testdb.c index e521e6b3..6d351ebd 100644 --- a/src/util/testdb.c +++ b/src/util/testdb.c @@ -92,6 +92,11 @@ static int db_test(char *dbpath, int local) } } } + if(closedir(dir)) { + fprintf(stderr, "error closing dbpath : %s\n", strerror(errno)); + return(1); + } + return(ret); } @@ -110,6 +115,7 @@ int checkdeps(alpm_list_t *pkglist) free(depstring); ret++; } + FREELIST(data); return(ret); } @@ -125,6 +131,7 @@ int checkconflicts(alpm_list_t *pkglist) alpm_conflict_get_package2(conflict)); ret++; } + FREELIST(data); return(ret); } @@ -163,21 +170,23 @@ int check_syncdbs(char *dbpath, alpm_list_t *dbnames) { snprintf(syncdbpath, PATH_MAX, "%s/sync/%s", dbpath, dbname); ret = db_test(syncdbpath, 0); if(ret) { - return(ret); + ret = 1; + goto cleanup; } db = alpm_db_register_sync(dbname); if(db == NULL) { fprintf(stderr, "error: could not register sync database (%s)\n", alpm_strerrorlast()); - cleanup(EXIT_FAILURE); + ret = 1; + goto cleanup; } pkglist = alpm_db_get_pkgcache(db); syncpkglist = alpm_list_join(syncpkglist, alpm_list_copy(pkglist)); } ret += checkdeps(syncpkglist); - alpm_list_free(syncpkglist); - alpm_db_unregister_all(); +cleanup: + alpm_list_free(syncpkglist); return(ret); } @@ -227,6 +236,7 @@ int main(int argc, char **argv) ret = check_localdb(dbpath); } else { ret = check_syncdbs(dbpath,dbnames); + alpm_list_free(dbnames); } cleanup(ret); -- cgit v1.2.3-70-g09d2