]> git.ipfire.org Git - thirdparty/zstd.git/commitdiff
[multiple-ddicts] Fix NULL checks 2817/head
authorNick Terrell <terrelln@fb.com>
Fri, 8 Oct 2021 18:05:58 +0000 (11:05 -0700)
committerNick Terrell <terrelln@fb.com>
Fri, 8 Oct 2021 18:24:58 +0000 (11:24 -0700)
The bug was reported by Dan Carpenter and found by Smatch static
checker.

https://lore.kernel.org/all/20211008063704.GA5370@kili/

lib/decompress/zstd_decompress.c

index 4a4b3f72ac4c2b704c9a4a9a152c1e657c4462b9..3307975a127c83d67cc14495f2e2ab9af8ad5c7a 100644 (file)
@@ -177,12 +177,15 @@ static const ZSTD_DDict* ZSTD_DDictHashSet_getDDict(ZSTD_DDictHashSet* hashSet,
 static ZSTD_DDictHashSet* ZSTD_createDDictHashSet(ZSTD_customMem customMem) {
     ZSTD_DDictHashSet* ret = (ZSTD_DDictHashSet*)ZSTD_customMalloc(sizeof(ZSTD_DDictHashSet), customMem);
     DEBUGLOG(4, "Allocating new hash set");
+    if (!ret)
+        return NULL;
     ret->ddictPtrTable = (const ZSTD_DDict**)ZSTD_customCalloc(DDICT_HASHSET_TABLE_BASE_SIZE * sizeof(ZSTD_DDict*), customMem);
-    ret->ddictPtrTableSize = DDICT_HASHSET_TABLE_BASE_SIZE;
-    ret->ddictPtrCount = 0;
-    if (!ret || !ret->ddictPtrTable) {
+    if (!ret->ddictPtrTable) {
+        ZSTD_customFree(ret, customMem);
         return NULL;
     }
+    ret->ddictPtrTableSize = DDICT_HASHSET_TABLE_BASE_SIZE;
+    ret->ddictPtrCount = 0;
     return ret;
 }