|
@@ -20,11 +20,12 @@
|
|
|
* @author Ioannis Koutras (joko@microlab.ntua.gr)
|
|
|
* @date September 2012
|
|
|
*
|
|
|
- * @brief Implementation free() call.
|
|
|
+ * @brief Implementation of the free() call.
|
|
|
*/
|
|
|
|
|
|
#include "dmmlib/dmmlib.h"
|
|
|
|
|
|
+#include <inttypes.h>
|
|
|
#include <stdbool.h>
|
|
|
|
|
|
#ifdef BITMAP_RB_ONLY
|
|
@@ -43,6 +44,7 @@
|
|
|
|
|
|
#include "release_memory.h"
|
|
|
|
|
|
+
|
|
|
#include "trace.h"
|
|
|
|
|
|
void free(void *ptr) {
|
|
@@ -59,8 +61,8 @@ void free(void *ptr) {
|
|
|
|
|
|
current_raw_block = systemallocator.raw_block_head;
|
|
|
while(current_raw_block) {
|
|
|
- if(((char *)ptr > (char *)current_raw_block) &&
|
|
|
- ((char *)ptr < (char *)(current_raw_block) +
|
|
|
+ if(((uintptr_t) ptr > (uintptr_t) current_raw_block) &&
|
|
|
+ ((uintptr_t) ptr < (uintptr_t) current_raw_block +
|
|
|
current_raw_block->size)) {
|
|
|
found = true;
|
|
|
break;
|
|
@@ -83,7 +85,7 @@ void free(void *ptr) {
|
|
|
#ifdef FL_RB_ONLY
|
|
|
(freelist_rb_t *)
|
|
|
#endif
|
|
|
- ((char *)current_raw_block + sizeof(raw_block_header_t));
|
|
|
+ ((uintptr_t) current_raw_block + sizeof(raw_block_header_t));
|
|
|
|
|
|
#ifdef HAVE_LOCKS
|
|
|
pthread_mutex_lock(¤t_raw_block->mutex);
|
|
@@ -95,8 +97,36 @@ void free(void *ptr) {
|
|
|
|
|
|
} else {
|
|
|
|
|
|
- current_raw_block = (raw_block_header_t *)((char *)ptr -
|
|
|
- sizeof(raw_block_header_t));
|
|
|
+ current_raw_block = (raw_block_header_t *)
|
|
|
+ ((uintptr_t) ptr - sizeof(raw_block_header_t));
|
|
|
+
|
|
|
+
|
|
|
+ * mode is on */
|
|
|
+#ifdef WITH_DEBUG
|
|
|
+ raw_block_header_t *previous_raw_block = NULL;
|
|
|
+
|
|
|
+ for(raw_block_header_t *block_in_list =
|
|
|
+ systemallocator.big_blocks_head;
|
|
|
+ block_in_list != NULL;
|
|
|
+ block_in_list = block_in_list->next_raw_block
|
|
|
+ ) {
|
|
|
+ if(block_in_list == current_raw_block) {
|
|
|
+ if(systemallocator.big_blocks_head == current_raw_block) {
|
|
|
+#ifdef HAVE_LOCKS
|
|
|
+ pthread_mutex_lock(&systemallocator.creation_mutex);
|
|
|
+#endif
|
|
|
+ systemallocator.big_blocks_head =
|
|
|
+ current_raw_block->next_raw_block;
|
|
|
+#ifdef HAVE_LOCKS
|
|
|
+ pthread_mutex_unlock(&systemallocator.creation_mutex);
|
|
|
+#endif
|
|
|
+ } else {
|
|
|
+ previous_raw_block->next_raw_block =
|
|
|
+ current_raw_block->next_raw_block;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+#endif
|
|
|
|
|
|
#ifdef WITH_ALLOCATOR_STATS
|
|
|
update_stats(&systemallocator.dmm_stats,
|