More debug allocator fixes and enhancements
authorMichael Poole <mdpoole@troilus.org>
Fri, 21 Jan 2005 15:10:49 +0000 (15:10 +0000)
committerMichael Poole <mdpoole@troilus.org>
Fri, 21 Jan 2005 15:10:49 +0000 (15:10 +0000)
src/alloc-srvx.c (*_MAGIC): ASk recognized the CCSDS ASM sequence.
(srvx_free): Overwrite with 0xDE bytes to distinguish from
uninitialized values.  As SailorFrag suggested, only overwrite the
user region.

src/dict-splay.c (dict_insert): Check whether free functions need to
be worked around here as well.
git-archimport-id: srvx@srvx.net--2005-srvx/srvx--devo--1.3--patch-6

ChangeLog
src/alloc-srvx.c
src/dict-splay.c

index 26989642f2a10902e1dcaada606aa0c92d8bb09f..198e29f67eacad7a2cf3247b56a4504bff275202 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -2,6 +2,25 @@
 # arch-tag: automatic-ChangeLog--srvx@srvx.net--2005-srvx/srvx--devo--1.3
 #
 
+2005-01-21 15:10:49 GMT        Michael Poole <mdpoole@troilus.org>     patch-6
+
+    Summary:
+      More debug allocator fixes and enhancements
+    Revision:
+      srvx--devo--1.3--patch-6
+
+    src/alloc-srvx.c (*_MAGIC): ASk recognized the CCSDS ASM sequence.
+    (srvx_free): Overwrite with 0xDE bytes to distinguish from
+    uninitialized values.  As SailorFrag suggested, only overwrite the
+    user region.
+    
+    src/dict-splay.c (dict_insert): Check whether free functions need to
+    be worked around here as well.
+
+    modified files:
+     ChangeLog src/alloc-srvx.c src/dict-splay.c
+
+
 2005-01-21 00:48:35 GMT        Michael Poole <mdpoole@troilus.org>     patch-5
 
     Summary:
index b8e1afab34cc18680d8f344b8a1c3df0b971d428..047cb95db528b2d5035d429bc7b47e62eb90e1fe 100644 (file)
@@ -19,7 +19,6 @@
 #undef malloc
 #undef free
 
-/* cookies for anybody who recognizes these bytes without help :) */
 #define ALLOC_MAGIC 0x1acf
 #define FREE_MAGIC  0xfc1d
 const char redzone[] = { '\x03', '\x47', '\x76', '\xc7' };
@@ -132,11 +131,11 @@ srvx_free(const char *file, unsigned int line, void *ptr)
     block = (struct alloc_header *)ptr - 1;
     assert(block->magic == ALLOC_MAGIC);
     assert(0 == memcmp((char*)(block + 1) + block->size, redzone, sizeof(redzone)));
-    size = block->size + sizeof(*block);
-    memset(block, 0, size);
+    size = block->size;
+    memset(block + 1, 0xde, size);
     block->magic = FREE_MAGIC;
     free(block);
     alloc_count--;
-    alloc_size -= size - sizeof(*block);
+    alloc_size -= size;
     (void)file; (void)line;
 }
index 4619ce562dc7ea516b5c4bc6fbe1705487818755..597545bfacd972a7648a54a41db00cef838f4fca 100644 (file)
@@ -186,8 +186,18 @@ dict_insert(dict_t dict, const char *key, void *data)
            dict->root = new_node;
        } else {
            /* maybe we don't want to overwrite it .. oh well */
-           if (dict->free_data) dict->free_data(dict->root->data);
-            if (dict->free_keys) dict->free_keys((void*)dict->root->key);
+           if (dict->free_data) {
+                if (dict->free_data == free)
+                    free(dict->root->data);
+                else
+                    dict->free_data(dict->root->data);
+            }
+            if (dict->free_keys) {
+                if (dict->free_keys == free)
+                    free((void*)dict->root->key);
+                else
+                    dict->free_keys((void*)dict->root->key);
+            }
             free(new_node);
             dict->root->key = key;
            dict->root->data = data;