Fix bug in dlmalloc's version of calloc.
Under some circumstances, doing a calloc will make sure that the memory returned will be zero up to the size of the requested size. However, if there is more usable size than the requested size, that extra part of the allocation will not be zeroed. This change fixes it so that the entire usable memory is always zeroed. Change-Id: I8a66d6767c074023c4ba3568bf2705e1886740fc
This commit is contained in:
@@ -4822,8 +4822,13 @@ void* dlcalloc(size_t n_elements, size_t elem_size) {
|
||||
req = MAX_SIZE_T; /* force downstream failure on overflow */
|
||||
}
|
||||
mem = dlmalloc(req);
|
||||
if (mem != 0 && calloc_must_clear(mem2chunk(mem)))
|
||||
memset(mem, 0, req);
|
||||
if (mem != 0) {
|
||||
mchunkptr p = mem2chunk(mem);
|
||||
if (calloc_must_clear(p)) {
|
||||
/* Make sure to clear all of the buffer, not just the requested size. */
|
||||
memset(mem, 0, chunksize(p) - overhead_for(p));
|
||||
}
|
||||
}
|
||||
return mem;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user