]> granicus.if.org Git - p11-kit/commitdiff
common: Don't do repeated linear reallocation of array memory
authorStef Walter <stef@thewalter.net>
Thu, 7 Aug 2014 06:38:46 +0000 (08:38 +0200)
committerStef Walter <stef@thewalter.net>
Thu, 7 Aug 2014 06:38:46 +0000 (08:38 +0200)
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

common/array.c

index 9802100851dd78970deb36644eef35a47f17e9f7..9bff7480f975bea11b03fe9b1faadd22168a3c38 100644 (file)
@@ -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;