diff options
author | Gerald Carter <jerry@samba.org> | 2000-08-10 13:58:15 +0000 |
---|---|---|
committer | Gerald Carter <jerry@samba.org> | 2000-08-10 13:58:15 +0000 |
commit | df51dc32f6ffc4fe2cebfaae5079417aad1ff34d (patch) | |
tree | 09ac152fa356ddf6ac4500c1377a172047b45124 /source/lib/talloc.c | |
parent | 880e81161640cd38540b06d982c592cbada51d40 (diff) | |
download | samba-df51dc32f6ffc4fe2cebfaae5079417aad1ff34d.tar.gz samba-df51dc32f6ffc4fe2cebfaae5079417aad1ff34d.tar.xz samba-df51dc32f6ffc4fe2cebfaae5079417aad1ff34d.zip |
talloc returns 0xdeadbeef when asked to allocate 0 bytes
jerry
Diffstat (limited to 'source/lib/talloc.c')
-rw-r--r-- | source/lib/talloc.c | 48 |
1 files changed, 29 insertions, 19 deletions
diff --git a/source/lib/talloc.c b/source/lib/talloc.c index 31594d2a01e..577f761072f 100644 --- a/source/lib/talloc.c +++ b/source/lib/talloc.c @@ -56,27 +56,37 @@ void *talloc(TALLOC_CTX *t, size_t size) { void *p; - size = (size + (TALLOC_ALIGN-1)) & ~(TALLOC_ALIGN-1); - - if (!t->list || (t->list->total_size - t->list->alloc_size) < size) { - struct talloc_chunk *c; - size_t asize = (size + (TALLOC_CHUNK_SIZE-1)) & ~(TALLOC_CHUNK_SIZE-1); - - c = (struct talloc_chunk *)malloc(sizeof(*c)); - if (!c) return NULL; - c->next = t->list; - c->ptr = (void *)malloc(asize); - if (!c->ptr) { - free(c); - return NULL; - } - c->alloc_size = 0; - c->total_size = asize; - t->list = c; + if (size == 0) + { + /* debugging value used to track down + memory problems */ + p = (void*)0xdeadbeef; } + else + { + size = (size + (TALLOC_ALIGN-1)) & ~(TALLOC_ALIGN-1); + + if (!t->list || (t->list->total_size - t->list->alloc_size) < size) { + struct talloc_chunk *c; + size_t asize = (size + (TALLOC_CHUNK_SIZE-1)) & ~(TALLOC_CHUNK_SIZE-1); + + c = (struct talloc_chunk *)malloc(sizeof(*c)); + if (!c) return NULL; + c->next = t->list; + c->ptr = (void *)malloc(asize); + if (!c->ptr) { + free(c); + return NULL; + } + c->alloc_size = 0; + c->total_size = asize; + t->list = c; + } - p = ((char *)t->list->ptr) + t->list->alloc_size; - t->list->alloc_size += size; + p = ((char *)t->list->ptr) + t->list->alloc_size; + t->list->alloc_size += size; + } + return p; } |