Fix AO_malloc for sizes near CHUNK_SIZE
authorIvan Maidanski <ivmai@mail.ru>
Mon, 4 Dec 2017 20:28:01 +0000 (23:28 +0300)
committerIvan Maidanski <ivmai@mail.ru>
Mon, 11 Dec 2017 07:22:53 +0000 (10:22 +0300)
Without this patch, e.g an object of CHUNK_SIZE is treated as non-large
in AO_malloc but freed by AO_free_large (incorrectly).

* src/atomic_ops_malloc.c (AO_malloc): Call AO_malloc_large() also for
size values in range CHUNK_SIZE-sizeof(AO_t)+1 .. CHUNK_SIZE.

src/atomic_ops_malloc.c

index 30703ab..2a69dbc 100644 (file)
@@ -300,7 +300,7 @@ AO_malloc(size_t sz)
   AO_t *result;
   unsigned log_sz;
 
-  if (sz > CHUNK_SIZE)
+  if (sz > CHUNK_SIZE - sizeof(AO_t))
     return AO_malloc_large(sz);
   log_sz = msb(sz + (sizeof(AO_t) - 1));
   result = AO_stack_pop(AO_free_list+log_sz);