From 1b3289745334ec31507a12b6c54b2883a521543e Mon Sep 17 00:00:00 2001 From: Rikard Falkeborn Date: Mon, 13 Apr 2020 07:28:48 +0200 Subject: 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 Signed-off-by: Allan McRae --- lib/libalpm/be_package.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'lib/libalpm/be_package.c') diff --git a/lib/libalpm/be_package.c b/lib/libalpm/be_package.c index 7a118d2a..4832966b 100644 --- a/lib/libalpm/be_package.c +++ b/lib/libalpm/be_package.c @@ -669,8 +669,7 @@ alpm_pkg_t *_alpm_pkg_load_internal(alpm_handle_t *handle, if(full) { if(newpkg->files.files) { /* attempt to hand back any memory we don't need */ - newpkg->files.files = realloc(newpkg->files.files, - sizeof(alpm_file_t) * newpkg->files.count); + REALLOC(newpkg->files.files, sizeof(alpm_file_t) * newpkg->files.count, (void)0); /* "checking for conflicts" requires a sorted list, ensure that here */ _alpm_log(handle, ALPM_LOG_DEBUG, "sorting package filelist for %s\n", pkgfile); -- cgit v1.2.3-24-g4f1b