summaryrefslogtreecommitdiffstats
path: root/lib/libalpm/be_sync.c
diff options
context:
space:
mode:
authorRikard Falkeborn <rikard.falkeborn@gmail.com>2020-04-13 07:28:48 +0200
committerAllan McRae <allan@archlinux.org>2020-04-13 15:44:46 +0200
commit1b3289745334ec31507a12b6c54b2883a521543e (patch)
treefea28e9b2f68178c5252f3c68cedccc1f766859f /lib/libalpm/be_sync.c
parent1d39557aa070d2260cfda650e59c8d190397ba01 (diff)
downloadpacman-1b3289745334ec31507a12b6c54b2883a521543e.tar.gz
pacman-1b3289745334ec31507a12b6c54b2883a521543e.tar.xz
Add REALLOC macro to simplify realloc error handling
realloc can fail just like the other memory allocation functions. Add a macro to simplify handling of realloc failures, similar to the already existing MALLOC, CALLOC, etc. Replace the existing realloc uses with the new macro, allowing us to move tedious error handling to the macro. Also, in be_package and be_sync, this fixes hypothetical memory leaks (and thereafter null pointer dereferences) in case realloc fails to shrink the allocated memory. Signed-off-by: Rikard Falkeborn <rikard.falkeborn@gmail.com> Signed-off-by: Allan McRae <allan@archlinux.org>
Diffstat (limited to 'lib/libalpm/be_sync.c')
-rw-r--r--lib/libalpm/be_sync.c2
1 files changed, 1 insertions, 1 deletions
diff --git a/lib/libalpm/be_sync.c b/lib/libalpm/be_sync.c
index aafed15d..5f457122 100644
--- a/lib/libalpm/be_sync.c
+++ b/lib/libalpm/be_sync.c
@@ -689,7 +689,7 @@ static int sync_db_read(alpm_db_t *db, struct archive *archive,
}
/* attempt to hand back any memory we don't need */
if(files_count > 0) {
- files = realloc(files, sizeof(alpm_file_t) * files_count);
+ REALLOC(files, sizeof(alpm_file_t) * files_count, (void)0);
} else {
FREE(files);
}