]> git.ipfire.org Git - thirdparty/zstd.git/commitdiff
fix : custom allocator correctly propagated to child contexts
authorYann Collet <cyan@fb.com>
Mon, 10 Jul 2017 21:21:40 +0000 (14:21 -0700)
committerYann Collet <cyan@fb.com>
Mon, 10 Jul 2017 21:21:40 +0000 (14:21 -0700)
lib/compress/zstdmt_compress.c
tests/fuzzer.c

index d5607adfd1ce12289a8b6ecf0dbc58c5b41d580a..bad2db9c2b776df18d7090822c8f9683dc447acb 100644 (file)
@@ -215,7 +215,7 @@ static ZSTD_CCtx* ZSTDMT_getCCtx(ZSTDMT_CCtxPool* pool)
         pool->availCCtx--;
         return pool->cctx[pool->availCCtx];
     }
-    return ZSTD_createCCtx();   /* note : can be NULL, when creation fails ! */
+    return ZSTD_createCCtx_advanced(pool->cMem);   /* note : can be NULL, when creation fails ! */
 }
 
 static void ZSTDMT_releaseCCtx(ZSTDMT_CCtxPool* pool, ZSTD_CCtx* cctx)
index c05ed5aea54212de791070e28cffa9aecf7a6807..aa1ebd48f462e9720d010c916182a218c6203aa1 100644 (file)
@@ -158,22 +158,21 @@ static int FUZ_mallocTests(unsigned seed, double compressibility)
 
     /* simple compression tests */
     {   int compressionLevel;
-        mallocCounter_t malcount = INIT_MALLOC_COUNTER;
-        ZSTD_customMem const cMem = { FUZ_mallocDebug, FUZ_freeDebug, &malcount };
         for (compressionLevel=1; compressionLevel<=6; compressionLevel++) {
+            mallocCounter_t malcount = INIT_MALLOC_COUNTER;
+            ZSTD_customMem const cMem = { FUZ_mallocDebug, FUZ_freeDebug, &malcount };
             ZSTD_CCtx* const cctx = ZSTD_createCCtx_advanced(cMem);
             ZSTD_compressCCtx(cctx, outBuffer, outSize, inBuffer, inSize, compressionLevel);
             ZSTD_freeCCtx(cctx);
             DISPLAYLEVEL(3, "compressCCtx level %i : ", compressionLevel);
             FUZ_displayMallocStats(malcount);
-            malcount = INIT_MALLOC_COUNTER;
     }   }
 
     /* streaming compression tests */
     {   int compressionLevel;
-        mallocCounter_t malcount = INIT_MALLOC_COUNTER;
-        ZSTD_customMem const cMem = { FUZ_mallocDebug, FUZ_freeDebug, &malcount };
         for (compressionLevel=1; compressionLevel<=6; compressionLevel++) {
+            mallocCounter_t malcount = INIT_MALLOC_COUNTER;
+            ZSTD_customMem const cMem = { FUZ_mallocDebug, FUZ_freeDebug, &malcount };
             ZSTD_CCtx* const cstream = ZSTD_createCStream_advanced(cMem);
             ZSTD_outBuffer out = { outBuffer, outSize, 0 };
             ZSTD_inBuffer in = { inBuffer, inSize, 0 };
@@ -183,16 +182,15 @@ static int FUZ_mallocTests(unsigned seed, double compressibility)
             ZSTD_freeCStream(cstream);
             DISPLAYLEVEL(3, "compressStream level %i : ", compressionLevel);
             FUZ_displayMallocStats(malcount);
-            malcount = INIT_MALLOC_COUNTER;
     }   }
 
     /* advanced MT API test */
     {   U32 nbThreads;
         for (nbThreads=1; nbThreads<=4; nbThreads++) {
             int compressionLevel;
-            mallocCounter_t malcount = INIT_MALLOC_COUNTER;
-            ZSTD_customMem const cMem = { FUZ_mallocDebug, FUZ_freeDebug, &malcount };
             for (compressionLevel=1; compressionLevel<=6; compressionLevel++) {
+                mallocCounter_t malcount = INIT_MALLOC_COUNTER;
+                ZSTD_customMem const cMem = { FUZ_mallocDebug, FUZ_freeDebug, &malcount };
                 ZSTD_CCtx* const cctx = ZSTD_createCCtx_advanced(cMem);
                 ZSTD_outBuffer out = { outBuffer, outSize, 0 };
                 ZSTD_inBuffer in = { inBuffer, inSize, 0 };
@@ -203,16 +201,15 @@ static int FUZ_mallocTests(unsigned seed, double compressibility)
                 DISPLAYLEVEL(3, "compress_generic,-T%u,end level %i : ",
                                 nbThreads, compressionLevel);
                 FUZ_displayMallocStats(malcount);
-                malcount = INIT_MALLOC_COUNTER;
     }   }   }
 
     /* advanced MT streaming API test */
     {   U32 nbThreads;
         for (nbThreads=1; nbThreads<=4; nbThreads++) {
             int compressionLevel;
-            mallocCounter_t malcount = INIT_MALLOC_COUNTER;
-            ZSTD_customMem const cMem = { FUZ_mallocDebug, FUZ_freeDebug, &malcount };
             for (compressionLevel=1; compressionLevel<=6; compressionLevel++) {
+                mallocCounter_t malcount = INIT_MALLOC_COUNTER;
+                ZSTD_customMem const cMem = { FUZ_mallocDebug, FUZ_freeDebug, &malcount };
                 ZSTD_CCtx* const cctx = ZSTD_createCCtx_advanced(cMem);
                 ZSTD_outBuffer out = { outBuffer, outSize, 0 };
                 ZSTD_inBuffer in = { inBuffer, inSize, 0 };
@@ -224,7 +221,6 @@ static int FUZ_mallocTests(unsigned seed, double compressibility)
                 DISPLAYLEVEL(3, "compress_generic,-T%u,continue level %i : ",
                                 nbThreads, compressionLevel);
                 FUZ_displayMallocStats(malcount);
-                malcount = INIT_MALLOC_COUNTER;
     }   }   }
 
     return 0;