]> git.ipfire.org Git - thirdparty/zstd.git/commitdiff
free cdictLocal faster, suggested by @terrelln
authorYann Collet <cyan@fb.com>
Wed, 21 Jun 2017 19:26:40 +0000 (12:26 -0700)
committerYann Collet <cyan@fb.com>
Wed, 21 Jun 2017 19:26:40 +0000 (12:26 -0700)
lib/compress/zstdmt_compress.c

index 499c531c7e876ce3c3f4d46e377f5f29ad4a85b4..f07143c1a936f0d35bc0a1611ada9a7c011684fc 100644 (file)
@@ -583,13 +583,14 @@ size_t ZSTDMT_initCStream_internal(ZSTDMT_CCtx* zcs,
     zcs->frameContentSize = pledgedSrcSize;
     if (dict) {
         ZSTD_freeCDict(zcs->cdictLocal);
-        zcs->cdict = NULL;
         zcs->cdictLocal = ZSTD_createCDict_advanced(dict, dictSize,
                                                     0 /* byRef */, ZSTD_dm_auto,
                                                     params.cParams, zcs->cMem);
-        if (zcs->cdictLocal == NULL) return ERROR(memory_allocation);
         zcs->cdict = zcs->cdictLocal;
+        if (zcs->cdictLocal == NULL) return ERROR(memory_allocation);
     } else {
+        ZSTD_freeCDict(zcs->cdictLocal);
+        zcs->cdictLocal = NULL;
         zcs->cdict = cdict;
     }
 
@@ -627,7 +628,7 @@ size_t ZSTDMT_initCStream_usingCDict(ZSTDMT_CCtx* mtctx,
                                      unsigned long long pledgedSrcSize)
 {
     ZSTD_parameters params = ZSTD_getParamsFromCDict(cdict);
-    if (cdict==NULL) return ERROR(GENERIC);   /* method incompatible with NULL cdict */
+    if (cdict==NULL) return ERROR(dictionary_wrong);   /* method incompatible with NULL cdict */
     params.fParams = fParams;
     return ZSTDMT_initCStream_internal(mtctx, NULL, 0 /*dictSize*/, cdict,
                                         params, pledgedSrcSize);