mirror of
https://github.com/facebook/zstd
synced 2026-08-22 22:32:07 -04:00
Fix potential NULL pointer dereference in ZSTD_customCalloc when custom allocator fails
This commit is contained in:
parent
d7ee3207cc
commit
3f8f9b3f89
1 changed files with 6 additions and 2 deletions
|
|
@ -33,9 +33,13 @@ MEM_STATIC void* ZSTD_customMalloc(size_t size, ZSTD_customMem customMem)
|
|||
MEM_STATIC void* ZSTD_customCalloc(size_t size, ZSTD_customMem customMem)
|
||||
{
|
||||
if (customMem.customAlloc) {
|
||||
/* calloc implemented as malloc+memset;
|
||||
* not as efficient as calloc, but next best guess for custom malloc */
|
||||
/* calloc implemented as malloc+memset */
|
||||
void* const ptr = customMem.customAlloc(customMem.opaque, size);
|
||||
|
||||
if (ptr == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
ZSTD_memset(ptr, 0, size);
|
||||
return ptr;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue