From 7a6b01d46c1da385dd34466e757beafa33e02afa Mon Sep 17 00:00:00 2001 From: Dan McGee Date: Wed, 26 Oct 2011 15:44:55 -0500 Subject: Don't realloc a 0-length files array when loading packages There is some pecular behavior going on here when a package is loaded that has no files, as is very common in our test suite. When we enter the realloc/sort code, a package without files will call the following: files = realloc(NULL, 0); One would assume this is a no-op, returning a NULL pointer, but that is not the case and valgrind later reports we are leaking memory. Fix the whole thing by skipping the reallocation and sort steps if the pointer is NULL, as we have nothing to do. Note that the package still gets marked as 'files loaded', becuase although there were none, we tried and were successful. Signed-off-by: Dan McGee --- lib/libalpm/be_package.c | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) (limited to 'lib/libalpm/be_package.c') diff --git a/lib/libalpm/be_package.c b/lib/libalpm/be_package.c index c20c703f..c8e08e22 100644 --- a/lib/libalpm/be_package.c +++ b/lib/libalpm/be_package.c @@ -482,17 +482,19 @@ alpm_pkg_t *_alpm_pkg_load_internal(alpm_handle_t *handle, newpkg->origin_data.file = strdup(pkgfile); newpkg->ops = get_file_pkg_ops(); newpkg->handle = handle; + newpkg->infolevel = INFRQ_BASE | INFRQ_DESC | INFRQ_SCRIPTLET; if(full) { - /* attempt to hand back any memory we don't need */ - files = realloc(files, sizeof(alpm_file_t) * files_count); - /* "checking for conflicts" requires a sorted list, ensure that here */ - _alpm_log(handle, ALPM_LOG_DEBUG, "sorting package filelist for %s\n", pkgfile); - newpkg->files.files = files_msort(files, files_count); + if(files) { + /* attempt to hand back any memory we don't need */ + files = realloc(files, sizeof(alpm_file_t) * files_count); + /* "checking for conflicts" requires a sorted list, ensure that here */ + _alpm_log(handle, ALPM_LOG_DEBUG, + "sorting package filelist for %s\n", pkgfile); + newpkg->files.files = files_msort(files, files_count); + } newpkg->files.count = files_count; - newpkg->infolevel = INFRQ_BASE | INFRQ_DESC | INFRQ_FILES | INFRQ_SCRIPTLET; - } else { - newpkg->infolevel = INFRQ_BASE | INFRQ_DESC | INFRQ_SCRIPTLET; + newpkg->infolevel |= INFRQ_FILES; } return newpkg; -- cgit v1.2.3 From 3343185473c79d556b29bda30c9c482c7fef5289 Mon Sep 17 00:00:00 2001 From: Dan McGee Date: Thu, 27 Oct 2011 14:59:24 -0500 Subject: Introduce ALPM_BUFFER_SIZE constant This takes the place of three previously used constants: ARCHIVE_DEFAULT_BYTES_PER_BLOCK, BUFFER_SIZE, and CPBUFSIZE. In libarchive 3.0, the first constant will be no more, so we can ensure we are forward-compatible by removing our usage of it now. The rest are unified for consistency. By default, we will use the value of BUFSIZ provided by , which is 8192 on Linux. If that is undefined, a default value is provided. Signed-off-by: Dan McGee --- lib/libalpm/be_package.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'lib/libalpm/be_package.c') diff --git a/lib/libalpm/be_package.c b/lib/libalpm/be_package.c index c8e08e22..4d9d0e82 100644 --- a/lib/libalpm/be_package.c +++ b/lib/libalpm/be_package.c @@ -59,7 +59,7 @@ static void *_package_changelog_open(alpm_pkg_t *pkg) archive_read_support_format_all(archive); if(archive_read_open_filename(archive, pkgfile, - ARCHIVE_DEFAULT_BYTES_PER_BLOCK) != ARCHIVE_OK) { + ALPM_BUFFER_SIZE) != ARCHIVE_OK) { RET_ERR(pkg->handle, ALPM_ERR_PKG_OPEN, NULL); } @@ -390,7 +390,7 @@ alpm_pkg_t *_alpm_pkg_load_internal(alpm_handle_t *handle, archive_read_support_format_all(archive); if(archive_read_open_filename(archive, pkgfile, - ARCHIVE_DEFAULT_BYTES_PER_BLOCK) != ARCHIVE_OK) { + ALPM_BUFFER_SIZE) != ARCHIVE_OK) { alpm_pkg_free(newpkg); RET_ERR(handle, ALPM_ERR_PKG_OPEN, NULL); } -- cgit v1.2.3