summaryrefslogtreecommitdiff
path: root/source3
diff options
context:
space:
mode:
authorGerald Carter <jerry@samba.org>2000-08-10 13:58:15 +0000
committerGerald Carter <jerry@samba.org>2000-08-10 13:58:15 +0000
commit0a86b83a86acbc048345bf0ddf6d0196ddc5b042 (patch)
treec9a48aad9f303ad8d24c5876f056f5eb567698e6 /source3
parent8e0e3196743c3d6aa9cd0cc9f5cece49b2e2323c (diff)
downloadsamba-0a86b83a86acbc048345bf0ddf6d0196ddc5b042.tar.gz
samba-0a86b83a86acbc048345bf0ddf6d0196ddc5b042.tar.bz2
samba-0a86b83a86acbc048345bf0ddf6d0196ddc5b042.zip
talloc returns 0xdeadbeef when asked to allocate 0 bytes
jerry (This used to be commit df51dc32f6ffc4fe2cebfaae5079417aad1ff34d)
Diffstat (limited to 'source3')
-rw-r--r--source3/lib/talloc.c48
1 files changed, 29 insertions, 19 deletions
diff --git a/source3/lib/talloc.c b/source3/lib/talloc.c
index 31594d2a01..577f761072 100644
--- a/source3/lib/talloc.c
+++ b/source3/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;
}