From: Michael Poole Date: Fri, 21 Jan 2005 15:10:49 +0000 (+0000) Subject: More debug allocator fixes and enhancements X-Git-Tag: v1.4.0-rc1~186 X-Git-Url: http://git.pk910.de/?p=srvx.git;a=commitdiff_plain;h=dea629dc3145fbd4de2f45ae7fbbe9bb44f71488 More debug allocator fixes and enhancements 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 --- diff --git a/ChangeLog b/ChangeLog index 2698964..198e29f 100644 --- 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 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 patch-5 Summary: diff --git a/src/alloc-srvx.c b/src/alloc-srvx.c index b8e1afa..047cb95 100644 --- a/src/alloc-srvx.c +++ b/src/alloc-srvx.c @@ -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; } diff --git a/src/dict-splay.c b/src/dict-splay.c index 4619ce5..597545b 100644 --- a/src/dict-splay.c +++ b/src/dict-splay.c @@ -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;