diff options
author | Dan McGee <dan@archlinux.org> | 2007-08-21 23:29:10 -0400 |
---|---|---|
committer | Dan McGee <dan@archlinux.org> | 2007-08-21 23:29:10 -0400 |
commit | 515754faacf9dd33b94e6e5a17ca04d27d61f482 (patch) | |
tree | 4788e1d46318b1fd21184696683ec779a9ec7ddb /lib/libalpm | |
parent | d09d114e99c29d1392c546a6553650ecde5138fc (diff) |
Various valgrind mem leak fixes
Signed-off-by: Dan McGee <dan@archlinux.org>
Diffstat (limited to 'lib/libalpm')
-rw-r--r-- | lib/libalpm/cache.c | 1 | ||||
-rw-r--r-- | lib/libalpm/db.c | 47 | ||||
-rw-r--r-- | lib/libalpm/db.h | 1 | ||||
-rw-r--r-- | lib/libalpm/server.c | 16 |
4 files changed, 38 insertions, 27 deletions
diff --git a/lib/libalpm/cache.c b/lib/libalpm/cache.c index 01abb96c..10021634 100644 --- a/lib/libalpm/cache.c +++ b/lib/libalpm/cache.c @@ -87,6 +87,7 @@ void _alpm_db_free_pkgcache(pmdb_t *db) for(tmp = db->pkgcache; tmp; tmp = alpm_list_next(tmp)) { _alpm_pkg_free(tmp->data); } + alpm_list_free(db->pkgcache); db->pkgcache = NULL; if(db->grpcache) { diff --git a/lib/libalpm/db.c b/lib/libalpm/db.c index 32ac48bc..0cb375dc 100644 --- a/lib/libalpm/db.c +++ b/lib/libalpm/db.c @@ -70,6 +70,20 @@ pmdb_t SYMEXPORT *alpm_db_register(const char *treename) return(_alpm_db_register(treename)); } +/* Helper function for alpm_db_unregister{_all} */ +static void _alpm_db_unregister(pmdb_t *db) +{ + if(db == NULL) { + return; + } + + _alpm_log(PM_LOG_DEBUG, "closing database '%s'", db->treename); + _alpm_db_close(db); + + _alpm_log(PM_LOG_DEBUG, "unregistering database '%s'", db->treename); + _alpm_db_free(db); +} + /** Unregister all package databases * @return 0 on success, -1 on error (pm_errno is set accordingly) */ @@ -120,12 +134,13 @@ int SYMEXPORT alpm_db_unregister(pmdb_t *db) handle->db_local = NULL; found = 1; } else { - /* Warning : this function shouldn't be used to unregister all sync databases - * by walking through the list returned by alpm_option_get_syncdbs, - * because the db is removed from that list here. + /* Warning : this function shouldn't be used to unregister all sync + * databases by walking through the list returned by + * alpm_option_get_syncdbs, because the db is removed from that list here. */ void *data; - handle->dbs_sync = alpm_list_remove(handle->dbs_sync, db, _alpm_db_cmp, &data); + handle->dbs_sync = alpm_list_remove(handle->dbs_sync, + db, _alpm_db_cmp, &data); if(data) { found = 1; } @@ -566,23 +581,6 @@ error: /** @} */ -/* Helper function for alpm_db_unregister{_all} */ -void _alpm_db_unregister(pmdb_t *db) -{ - if(db == NULL) { - return; - } - _alpm_log(PM_LOG_DEBUG, "unregistering database '%s'", db->treename); - - /* Cleanup */ - _alpm_db_free_pkgcache(db); - - _alpm_log(PM_LOG_DEBUG, "closing database '%s'", db->treename); - _alpm_db_close(db); - - _alpm_db_free(db); -} - pmdb_t *_alpm_db_new(const char *dbpath, const char *treename) { pmdb_t *db; @@ -611,12 +609,17 @@ pmdb_t *_alpm_db_new(const char *dbpath, const char *treename) void _alpm_db_free(pmdb_t *db) { + alpm_list_t *tmp; + ALPM_LOG_FUNC; - alpm_list_t *tmp; + /* cleanup pkgcache */ + _alpm_db_free_pkgcache(db); + /* cleanup server list */ for(tmp = db->servers; tmp; tmp = alpm_list_next(tmp)) { _alpm_server_free(tmp->data); } + alpm_list_free(db->servers); FREE(db->path); FREE(db); diff --git a/lib/libalpm/db.h b/lib/libalpm/db.h index d31bf60e..2597c8c4 100644 --- a/lib/libalpm/db.h +++ b/lib/libalpm/db.h @@ -53,7 +53,6 @@ void _alpm_db_free(pmdb_t *db); int _alpm_db_cmp(const void *db1, const void *db2); alpm_list_t *_alpm_db_search(pmdb_t *db, const alpm_list_t *needles); pmdb_t *_alpm_db_register(const char *treename); -void _alpm_db_unregister(pmdb_t *db); /* be.c, backend specific calls */ int _alpm_db_install(pmdb_t *db, const char *dbfile); diff --git a/lib/libalpm/server.c b/lib/libalpm/server.c index a1456a0a..6c74850e 100644 --- a/lib/libalpm/server.c +++ b/lib/libalpm/server.c @@ -244,6 +244,7 @@ int _alpm_downloadfiles_forreal(alpm_list_t *servers, const char *localpath, fclose(localf); } /* try the next server */ + downloadFreeURL(fileurl); continue; } else { _alpm_log(PM_LOG_DEBUG, "connected to %s successfully", fileurl->host); @@ -261,6 +262,7 @@ int _alpm_downloadfiles_forreal(alpm_list_t *servers, const char *localpath, if(dlf != NULL) { fclose(dlf); } + downloadFreeURL(fileurl); return(1); } } @@ -287,7 +289,8 @@ int _alpm_downloadfiles_forreal(alpm_list_t *servers, const char *localpath, if(dlf != NULL) { fclose(dlf); } - return -1; + downloadFreeURL(fileurl); + return(-1); } } @@ -302,6 +305,7 @@ int _alpm_downloadfiles_forreal(alpm_list_t *servers, const char *localpath, fn, downloadLastErrString); fclose(localf); fclose(dlf); + downloadFreeURL(fileurl); return(-1); } @@ -313,6 +317,7 @@ int _alpm_downloadfiles_forreal(alpm_list_t *servers, const char *localpath, realfile, strerror(errno)); fclose(localf); fclose(dlf); + downloadFreeURL(fileurl); return(-1); } } @@ -324,7 +329,7 @@ int _alpm_downloadfiles_forreal(alpm_list_t *servers, const char *localpath, if(handle->dlcb) handle->dlcb(pkgname, dltotal_bytes, ust.size); } - + downloadFreeURL(fileurl); fclose(localf); fclose(dlf); rename(output, realfile); @@ -339,7 +344,10 @@ int _alpm_downloadfiles_forreal(alpm_list_t *servers, const char *localpath, char cwd[PATH_MAX]; /* build the full download url */ - snprintf(url, PATH_MAX, "%s://%s%s", fileurl->scheme, fileurl->host, fileurl->doc); + snprintf(url, PATH_MAX, "%s://%s%s", fileurl->scheme, + fileurl->host, fileurl->doc); + /* we don't need this anymore */ + downloadFreeURL(fileurl); /* replace all occurrences of %o with fn.part */ strncpy(origCmd, handle->xfercommand, sizeof(origCmd)); @@ -387,12 +395,12 @@ int _alpm_downloadfiles_forreal(alpm_list_t *servers, const char *localpath, } chdir(cwd); } - downloadFreeURL(fileurl); } if(alpm_list_count(complete) == alpm_list_count(files)) { done = 1; } + alpm_list_free(complete); } return(done ? 0 : -1); |