diff options
author | Tobias Stoeckmann <tobias@stoeckmann.org> | 2016-06-06 20:12:30 +0200 |
---|---|---|
committer | Andrew Gregory <andrew.gregory.8@gmail.com> | 2017-05-08 23:27:41 -0400 |
commit | 8abb0cbf0e76bc9e59aa58b368ca11a2f0c189f2 (patch) | |
tree | 29bed21bbaba10aeac3f34a54aea0e2e672e25dd /lib/libalpm/be_local.c | |
parent | e03c5392883a39be1bf46a4d5811d2c46359d196 (diff) | |
download | pacman-8abb0cbf0e76bc9e59aa58b368ca11a2f0c189f2.tar.xz |
Release resources on error paths.
Some resources (memory or file descriptors) are not released on all
error paths.
Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
Signed-off-by: Allan McRae <allan@archlinux.org>
(cherry picked from commit 681509fd445ed6012e6ecf89b49e9c00d83b70cd)
Diffstat (limited to 'lib/libalpm/be_local.c')
-rw-r--r-- | lib/libalpm/be_local.c | 19 |
1 files changed, 16 insertions, 3 deletions
diff --git a/lib/libalpm/be_local.c b/lib/libalpm/be_local.c index f8178228..cc2d8bad 100644 --- a/lib/libalpm/be_local.c +++ b/lib/libalpm/be_local.c @@ -800,18 +800,24 @@ static int local_db_read(alpm_pkg_t *info, alpm_dbinfrq_t inforeq) (len = _alpm_strip_newline(line, 0))) { if(!_alpm_greedy_grow((void **)&files, &files_size, (files_count ? (files_count + 1) * sizeof(alpm_file_t) : 8 * sizeof(alpm_file_t)))) { - goto error; + goto nomem; } /* since we know the length of the file string already, * we can do malloc + memcpy rather than strdup */ len += 1; - MALLOC(files[files_count].name, len, goto error); + MALLOC(files[files_count].name, len, goto nomem); memcpy(files[files_count].name, line, len); files_count++; } /* attempt to hand back any memory we don't need */ if(files_count > 0) { - files = realloc(files, sizeof(alpm_file_t) * files_count); + alpm_file_t *newfiles; + + newfiles = realloc(files, sizeof(alpm_file_t) * files_count); + if(newfiles != NULL) { + files = newfiles; + } + /* make sure the list is sorted */ qsort(files, files_count, sizeof(alpm_file_t), _alpm_files_cmp); } else { @@ -819,6 +825,13 @@ static int local_db_read(alpm_pkg_t *info, alpm_dbinfrq_t inforeq) } info->files.count = files_count; info->files.files = files; + continue; +nomem: + while(files_count > 0) { + FREE(files[--files_count].name); + } + FREE(files); + goto error; } else if(strcmp(line, "%BACKUP%") == 0) { while(safe_fgets(line, sizeof(line), fp) && _alpm_strip_newline(line, 0)) { alpm_backup_t *backup; |