|
@@ -35,6 +35,7 @@
|
|
|
#include <inttypes.h>
|
|
|
#endif /* HAVE_LOCKS */
|
|
|
#include "locks.h"
|
|
|
+#include "other.h"
|
|
|
|
|
|
/**
|
|
|
* Re-allocates a memory block from a freelist-organized raw block
|
|
@@ -50,6 +51,8 @@ void * freelist_realloc(freelist_rb_t *raw_block, void *ptr,
|
|
|
block_header_t *block;
|
|
|
void *ret;
|
|
|
|
|
|
+ req_size = req_padding(req_size);
|
|
|
+
|
|
|
block = get_header(ptr);
|
|
|
|
|
|
if(get_size(block) > req_size) {
|
|
@@ -66,6 +69,9 @@ void * freelist_realloc(freelist_rb_t *raw_block, void *ptr,
|
|
|
/* First try to allocate space from the same raw block.
|
|
|
* If it fails, try a more generic malloc. */
|
|
|
|
|
|
+ /* TODO check if the next memory block is free and try to coalesce if
|
|
|
+ * possible */
|
|
|
+
|
|
|
LOCK_RAW_BLOCK(rb);
|
|
|
ret = freelist_malloc(raw_block, req_size);
|
|
|
UNLOCK_RAW_BLOCK(rb);
|
|
@@ -78,7 +84,7 @@ void * freelist_realloc(freelist_rb_t *raw_block, void *ptr,
|
|
|
return NULL;
|
|
|
}
|
|
|
|
|
|
- memcpy(ret, ptr, block->size);
|
|
|
+ memcpy(ret, ptr, get_size(block));
|
|
|
|
|
|
LOCK_RAW_BLOCK(rb);
|
|
|
freelist_free(raw_block, ptr);
|