From: Stef Walter Date: Thu, 7 Aug 2014 06:38:46 +0000 (+0200) Subject: common: Don't do repeated linear reallocation of array memory X-Git-Tag: 0.21.1~2 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=4f2cc97a95733e9ea8f85510b0f1e5c99053ae5e;p=p11-kit common: Don't do repeated linear reallocation of array memory Some mallocs (notably on Windows) have really poor behavior when called repeatedly with a linearly growing buffer. https://bugzilla.redhat.com/show_bug.cgi?id=985419 --- diff --git a/common/array.c b/common/array.c index 9802100..9bff748 100644 --- a/common/array.c +++ b/common/array.c @@ -48,7 +48,10 @@ maybe_expand_array (p11_array *array, if (length <= array->allocated) return true; - new_allocated = array->allocated + 16; + + new_allocated = array->allocated * 2; + if (new_allocated == 0) + new_allocated = 16; if (new_allocated < length) new_allocated = length;