From 21281e9b69fa061bb64b6fb4e25f04bd0e530554 Mon Sep 17 00:00:00 2001 From: Daniel Micay Date: Wed, 14 Jan 2015 07:21:29 -0500 Subject: be_local: fix _alpm_greedy_grow usage The files_size variable contains the current capacity (in bytes) and should not be used to calculate the next length increment. It only works because _alpm_greedy_grow currently results in incremental growth. Signed-off-by: Daniel Micay Signed-off-by: Allan McRae --- lib/libalpm/be_local.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lib') diff --git a/lib/libalpm/be_local.c b/lib/libalpm/be_local.c index 93763966..7d141c6d 100644 --- a/lib/libalpm/be_local.c +++ b/lib/libalpm/be_local.c @@ -780,7 +780,7 @@ static int local_db_read(alpm_pkg_t *info, alpm_dbinfrq_t inforeq) while(safe_fgets(line, sizeof(line), fp) && (len = _alpm_strip_newline(line, 0))) { if(!_alpm_greedy_grow((void **)&files, &files_size, - (files_size ? files_size + sizeof(alpm_file_t) : 8 * sizeof(alpm_file_t)))) { + (files_count ? (files_count + 1) * sizeof(alpm_file_t) : 8 * sizeof(alpm_file_t)))) { goto error; } /* since we know the length of the file string already, -- cgit v1.2.3-70-g09d2 From c6263da168f7d612ea221e868fe42ad2ed706fa9 Mon Sep 17 00:00:00 2001 From: Daniel Micay Date: Wed, 14 Jan 2015 07:27:41 -0500 Subject: fix geometric growth in _alpm_greedy_grow It was allocating the required size rather than the calculated new size, resulting in pathological incremental reallocations. Signed-off-by: Daniel Micay Signed-off-by: Allan McRae --- lib/libalpm/util.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lib') diff --git a/lib/libalpm/util.c b/lib/libalpm/util.c index 43d0d7be..1e367369 100644 --- a/lib/libalpm/util.c +++ b/lib/libalpm/util.c @@ -1326,7 +1326,7 @@ void *_alpm_greedy_grow(void **data, size_t *current, const size_t required) return NULL; } - return _alpm_realloc(data, current, required); + return _alpm_realloc(data, current, newsize); } void _alpm_alloc_fail(size_t size) -- cgit v1.2.3-70-g09d2