[pacman-dev] [PATCH] Plug various minor memory leaks
Signed-off-by: Andrew Gregory <andrew.gregory.8@gmail.com> --- lib/libalpm/be_local.c | 1 + lib/libalpm/dload.c | 1 + lib/libalpm/sync.c | 2 +- src/pacman/pacman.c | 5 +++-- src/pacman/util.c | 2 ++ 5 files changed, 8 insertions(+), 3 deletions(-) diff --git a/lib/libalpm/be_local.c b/lib/libalpm/be_local.c index 5a37463..8f82374 100644 --- a/lib/libalpm/be_local.c +++ b/lib/libalpm/be_local.c @@ -1018,6 +1018,7 @@ int _alpm_local_db_remove(alpm_db_t *db, alpm_pkg_t *info) dirp = opendir(pkgpath); if(!dirp) { + free(pkgpath); return -1; } /* go through the local DB entry, removing the files within, which we know diff --git a/lib/libalpm/dload.c b/lib/libalpm/dload.c index 6aaff1d..3e1659e 100644 --- a/lib/libalpm/dload.c +++ b/lib/libalpm/dload.c @@ -358,6 +358,7 @@ static FILE *create_tempfile(struct dload_payload *payload, const char *localpat CLOSE(fd); _alpm_log(payload->handle, ALPM_LOG_ERROR, _("failed to create temporary file for download\n")); + free(randpath); return NULL; } /* fp now points to our alpmtmp.XXXXXX */ diff --git a/lib/libalpm/sync.c b/lib/libalpm/sync.c index ff1efcc..d99020a 100644 --- a/lib/libalpm/sync.c +++ b/lib/libalpm/sync.c @@ -709,7 +709,7 @@ static int apply_deltas(alpm_handle_t *handle) snprintf(from, len, "%s/%s", cachedir, d->from); } len = strlen(cachedir) + strlen(d->to) + 2; - MALLOC(to, len, RET_ERR(handle, ALPM_ERR_MEMORY, 1)); + MALLOC(to, len, free(from); RET_ERR(handle, ALPM_ERR_MEMORY, 1)); snprintf(to, len, "%s/%s", cachedir, d->to); /* build the patch command */ diff --git a/src/pacman/pacman.c b/src/pacman/pacman.c index b529265..e86b5c7 100644 --- a/src/pacman/pacman.c +++ b/src/pacman/pacman.c @@ -811,10 +811,11 @@ int main(int argc, char *argv[]) /* we support reading targets from stdin if a cmdline parameter is '-' */ if(!isatty(fileno(stdin)) && alpm_list_find_str(pm_targets, "-")) { size_t current_size = PATH_MAX; - char *line = malloc(current_size); + char *vdata, *line = malloc(current_size); /* remove the '-' from the list */ - pm_targets = alpm_list_remove_str(pm_targets, "-", NULL); + pm_targets = alpm_list_remove_str(pm_targets, "-", &vdata); + free(vdata); i = 0; while((line[i] = (char)fgetc(stdin)) != EOF) { diff --git a/src/pacman/util.c b/src/pacman/util.c index 2bd9d99..e8060cd 100644 --- a/src/pacman/util.c +++ b/src/pacman/util.c @@ -510,6 +510,8 @@ static size_t table_calc_widths(const alpm_list_t *header, colwidths = malloc(totalcols * sizeof(size_t)); coldata = calloc(totalcols, sizeof(int)); if(!colwidths || !coldata) { + free(colwidths); + free(coldata); return 0; } /* header determines column count and initial values of longest_strs */ -- 1.8.0
participants (1)
-
Andrew Gregory