1
0
mirror of https://github.com/moparisthebest/pacman synced 2024-12-23 00:08:50 -05:00

Various valgrind mem leak fixes

Signed-off-by: Dan McGee <dan@archlinux.org>
This commit is contained in:
Dan McGee 2007-08-21 23:29:10 -04:00
parent d09d114e99
commit 515754faac
5 changed files with 43 additions and 29 deletions

View File

@ -87,6 +87,7 @@ void _alpm_db_free_pkgcache(pmdb_t *db)
for(tmp = db->pkgcache; tmp; tmp = alpm_list_next(tmp)) { for(tmp = db->pkgcache; tmp; tmp = alpm_list_next(tmp)) {
_alpm_pkg_free(tmp->data); _alpm_pkg_free(tmp->data);
} }
alpm_list_free(db->pkgcache);
db->pkgcache = NULL; db->pkgcache = NULL;
if(db->grpcache) { if(db->grpcache) {

View File

@ -70,6 +70,20 @@ pmdb_t SYMEXPORT *alpm_db_register(const char *treename)
return(_alpm_db_register(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 /** Unregister all package databases
* @return 0 on success, -1 on error (pm_errno is set accordingly) * @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; handle->db_local = NULL;
found = 1; found = 1;
} else { } else {
/* Warning : this function shouldn't be used to unregister all sync databases /* Warning : this function shouldn't be used to unregister all sync
* by walking through the list returned by alpm_option_get_syncdbs, * databases by walking through the list returned by
* because the db is removed from that list here. * alpm_option_get_syncdbs, because the db is removed from that list here.
*/ */
void *data; 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) { if(data) {
found = 1; 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 *_alpm_db_new(const char *dbpath, const char *treename)
{ {
pmdb_t *db; 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) void _alpm_db_free(pmdb_t *db)
{ {
alpm_list_t *tmp;
ALPM_LOG_FUNC; 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)) { for(tmp = db->servers; tmp; tmp = alpm_list_next(tmp)) {
_alpm_server_free(tmp->data); _alpm_server_free(tmp->data);
} }
alpm_list_free(db->servers);
FREE(db->path); FREE(db->path);
FREE(db); FREE(db);

View File

@ -53,7 +53,6 @@ void _alpm_db_free(pmdb_t *db);
int _alpm_db_cmp(const void *db1, const void *db2); int _alpm_db_cmp(const void *db1, const void *db2);
alpm_list_t *_alpm_db_search(pmdb_t *db, const alpm_list_t *needles); alpm_list_t *_alpm_db_search(pmdb_t *db, const alpm_list_t *needles);
pmdb_t *_alpm_db_register(const char *treename); pmdb_t *_alpm_db_register(const char *treename);
void _alpm_db_unregister(pmdb_t *db);
/* be.c, backend specific calls */ /* be.c, backend specific calls */
int _alpm_db_install(pmdb_t *db, const char *dbfile); int _alpm_db_install(pmdb_t *db, const char *dbfile);

View File

@ -244,6 +244,7 @@ int _alpm_downloadfiles_forreal(alpm_list_t *servers, const char *localpath,
fclose(localf); fclose(localf);
} }
/* try the next server */ /* try the next server */
downloadFreeURL(fileurl);
continue; continue;
} else { } else {
_alpm_log(PM_LOG_DEBUG, "connected to %s successfully", fileurl->host); _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) { if(dlf != NULL) {
fclose(dlf); fclose(dlf);
} }
downloadFreeURL(fileurl);
return(1); return(1);
} }
} }
@ -287,7 +289,8 @@ int _alpm_downloadfiles_forreal(alpm_list_t *servers, const char *localpath,
if(dlf != NULL) { if(dlf != NULL) {
fclose(dlf); 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); fn, downloadLastErrString);
fclose(localf); fclose(localf);
fclose(dlf); fclose(dlf);
downloadFreeURL(fileurl);
return(-1); return(-1);
} }
@ -313,6 +317,7 @@ int _alpm_downloadfiles_forreal(alpm_list_t *servers, const char *localpath,
realfile, strerror(errno)); realfile, strerror(errno));
fclose(localf); fclose(localf);
fclose(dlf); fclose(dlf);
downloadFreeURL(fileurl);
return(-1); 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); if(handle->dlcb) handle->dlcb(pkgname, dltotal_bytes, ust.size);
} }
downloadFreeURL(fileurl);
fclose(localf); fclose(localf);
fclose(dlf); fclose(dlf);
rename(output, realfile); rename(output, realfile);
@ -339,7 +344,10 @@ int _alpm_downloadfiles_forreal(alpm_list_t *servers, const char *localpath,
char cwd[PATH_MAX]; char cwd[PATH_MAX];
/* build the full download url */ /* 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 */ /* replace all occurrences of %o with fn.part */
strncpy(origCmd, handle->xfercommand, sizeof(origCmd)); strncpy(origCmd, handle->xfercommand, sizeof(origCmd));
@ -387,12 +395,12 @@ int _alpm_downloadfiles_forreal(alpm_list_t *servers, const char *localpath,
} }
chdir(cwd); chdir(cwd);
} }
downloadFreeURL(fileurl);
} }
if(alpm_list_count(complete) == alpm_list_count(files)) { if(alpm_list_count(complete) == alpm_list_count(files)) {
done = 1; done = 1;
} }
alpm_list_free(complete);
} }
return(done ? 0 : -1); return(done ? 0 : -1);

View File

@ -507,8 +507,7 @@ static int _parseconfig(const char *file, const char *givensection,
} }
} else { } else {
/* directive */ /* directive */
char *key; char *key, *upperkey;
const char *upperkey;
/* strsep modifies the 'line' string: 'key \0 ptr' */ /* strsep modifies the 'line' string: 'key \0 ptr' */
key = line; key = line;
ptr = line; ptr = line;
@ -677,9 +676,13 @@ static int _parseconfig(const char *file, const char *givensection,
return(1); return(1);
} }
} }
free(upperkey);
} }
} }
fclose(fp); fclose(fp);
if(section){
free(section);
}
pm_printf(PM_LOG_DEBUG, "config: finished parsing %s\n", file); pm_printf(PM_LOG_DEBUG, "config: finished parsing %s\n", file);
return(0); return(0);