mirror of
https://github.com/samba-team/samba.git
synced 2025-12-14 20:23:54 +03:00
talloc returns 0xdeadbeef when asked to allocate 0 bytes
jerry
This commit is contained in:
@@ -56,27 +56,37 @@ void *talloc(TALLOC_CTX *t, size_t size)
|
|||||||
{
|
{
|
||||||
void *p;
|
void *p;
|
||||||
|
|
||||||
size = (size + (TALLOC_ALIGN-1)) & ~(TALLOC_ALIGN-1);
|
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) {
|
if (!t->list || (t->list->total_size - t->list->alloc_size) < size) {
|
||||||
struct talloc_chunk *c;
|
struct talloc_chunk *c;
|
||||||
size_t asize = (size + (TALLOC_CHUNK_SIZE-1)) & ~(TALLOC_CHUNK_SIZE-1);
|
size_t asize = (size + (TALLOC_CHUNK_SIZE-1)) & ~(TALLOC_CHUNK_SIZE-1);
|
||||||
|
|
||||||
c = (struct talloc_chunk *)malloc(sizeof(*c));
|
c = (struct talloc_chunk *)malloc(sizeof(*c));
|
||||||
if (!c) return NULL;
|
if (!c) return NULL;
|
||||||
c->next = t->list;
|
c->next = t->list;
|
||||||
c->ptr = (void *)malloc(asize);
|
c->ptr = (void *)malloc(asize);
|
||||||
if (!c->ptr) {
|
if (!c->ptr) {
|
||||||
free(c);
|
free(c);
|
||||||
return NULL;
|
return NULL;
|
||||||
|
}
|
||||||
|
c->alloc_size = 0;
|
||||||
|
c->total_size = asize;
|
||||||
|
t->list = c;
|
||||||
}
|
}
|
||||||
c->alloc_size = 0;
|
|
||||||
c->total_size = asize;
|
p = ((char *)t->list->ptr) + t->list->alloc_size;
|
||||||
t->list = c;
|
t->list->alloc_size += size;
|
||||||
}
|
}
|
||||||
|
|
||||||
p = ((char *)t->list->ptr) + t->list->alloc_size;
|
|
||||||
t->list->alloc_size += size;
|
|
||||||
return p;
|
return p;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user