]> git.ipfire.org Git - thirdparty/zstd.git/commitdiff
[libzstd] Free local cdict when referencing cdict 1549/head
authorNick Terrell <terrelln@fb.com>
Wed, 13 Mar 2019 21:54:31 +0000 (14:54 -0700)
committerNick Terrell <terrelln@fb.com>
Wed, 13 Mar 2019 21:54:31 +0000 (14:54 -0700)
We no longer care about the `cdictLocal` after calling
`ZSTD_CCtx_refCDict()`, so we should free it to save some
memory.

lib/compress/zstd_compress.c

index 3d4091455a753eab608a7bd148c6ad6ae0be7e07..8de58b709649e9da6652dae56b115f8e18756a0d 100644 (file)
@@ -839,6 +839,9 @@ ZSTDLIB_API size_t ZSTD_CCtx_loadDictionary(ZSTD_CCtx* cctx, const void* dict, s
 size_t ZSTD_CCtx_refCDict(ZSTD_CCtx* cctx, const ZSTD_CDict* cdict)
 {
     RETURN_ERROR_IF(cctx->streamStage != zcss_init, stage_wrong);
+    /* Free the existing local cdict (if any) to save memory. */
+    FORWARD_IF_ERROR( ZSTD_freeCDict(cctx->cdictLocal) );
+    cctx->cdictLocal = NULL;
     cctx->cdict = cdict;
     memset(&cctx->prefixDict, 0, sizeof(cctx->prefixDict));  /* exclusive */
     return 0;