]> git.ipfire.org Git - thirdparty/zstd.git/commitdiff
fixed: deallocation of structures in case of error in ZBUFF_createCCtx and ZBUFF_crea...
authorinikep <inikep@gmail.com>
Fri, 3 Jun 2016 14:36:50 +0000 (16:36 +0200)
committerinikep <inikep@gmail.com>
Fri, 3 Jun 2016 14:36:50 +0000 (16:36 +0200)
lib/compress/zbuff_compress.c
lib/compress/zstd_compress.c
lib/decompress/zbuff_decompress.c
lib/decompress/zstd_decompress.c
zlibWrapper/Makefile

index 0340eeb35a9b242b568e84f238be1efa217bcaa4..fe8c3801e127e4a7f2ea9cb55d15b80db94117f4 100644 (file)
@@ -118,6 +118,7 @@ ZBUFF_CCtx* ZBUFF_createCCtx_advanced(ZSTD_customMem customMem)
     memset(zbc, 0, sizeof(ZBUFF_CCtx));
     memcpy(&zbc->customMem, &customMem, sizeof(ZSTD_customMem));
     zbc->zc = ZSTD_createCCtx_advanced(customMem);
+    if (zbc->zc == NULL) { ZBUFF_freeCCtx(zbc); return NULL; }
     return zbc;
 }
 
@@ -125,8 +126,8 @@ size_t ZBUFF_freeCCtx(ZBUFF_CCtx* zbc)
 {
     if (zbc==NULL) return 0;   /* support free on NULL */
     ZSTD_freeCCtx(zbc->zc);
-    zbc->customMem.customFree(zbc->customMem.opaque, zbc->inBuff);
-    zbc->customMem.customFree(zbc->customMem.opaque, zbc->outBuff);
+    if (zbc->inBuff) zbc->customMem.customFree(zbc->customMem.opaque, zbc->inBuff);
+    if (zbc->outBuff) zbc->customMem.customFree(zbc->customMem.opaque, zbc->outBuff);
     zbc->customMem.customFree(zbc->customMem.opaque, zbc);
     return 0;
 }
index 68a6072e84493d6afd8a4ab01e6875bfc2f89ea2..dbc9dd2061547c5f9e901f9884648f3022a5a7c1 100644 (file)
@@ -143,7 +143,8 @@ ZSTD_CCtx* ZSTD_createCCtx_advanced(ZSTD_customMem customMem)
 
 size_t ZSTD_freeCCtx(ZSTD_CCtx* cctx)
 {
-    cctx->customMem.customFree(cctx->customMem.opaque, cctx->workSpace);
+    if (cctx==NULL) return 0;   /* support free on NULL */
+    if (cctx->workSpace) cctx->customMem.customFree(cctx->customMem.opaque, cctx->workSpace);
     cctx->customMem.customFree(cctx->customMem.opaque, cctx);
     return 0;   /* reserved as a potential error code in the future */
 }
index e9e84ef7c2935f3f51fc2dd97374e9fcdf2503f7..01937bb068dca51165aff3f958f227f2555f4d1b 100644 (file)
@@ -106,6 +106,7 @@ ZBUFF_DCtx* ZBUFF_createDCtx_advanced(ZSTD_customMem customMem)
     memset(zbd, 0, sizeof(ZBUFF_DCtx));
     memcpy(&zbd->customMem, &customMem, sizeof(ZSTD_customMem));
     zbd->zd = ZSTD_createDCtx_advanced(customMem);
+    if (zbd->zd == NULL) { ZBUFF_freeDCtx(zbd); return NULL; }
     zbd->stage = ZBUFFds_init;
     return zbd;
 }
@@ -114,8 +115,8 @@ size_t ZBUFF_freeDCtx(ZBUFF_DCtx* zbd)
 {
     if (zbd==NULL) return 0;   /* support free on null */
     ZSTD_freeDCtx(zbd->zd);
-    zbd->customMem.customFree(zbd->customMem.opaque, zbd->inBuff);
-    zbd->customMem.customFree(zbd->customMem.opaque, zbd->outBuff);
+    if (zbd->inBuff) zbd->customMem.customFree(zbd->customMem.opaque, zbd->inBuff);
+    if (zbd->outBuff) zbd->customMem.customFree(zbd->customMem.opaque, zbd->outBuff);
     zbd->customMem.customFree(zbd->customMem.opaque, zbd);
     return 0;
 }
index 128d941eb86e7e907a935179f745e529d45a8eb4..cb2faab79d1f4537fbae0b4f749955cf0b749e95 100644 (file)
@@ -172,6 +172,7 @@ ZSTD_DCtx* ZSTD_createDCtx(void)
 
 size_t ZSTD_freeDCtx(ZSTD_DCtx* dctx)
 {
+    if (dctx==NULL) return 0;   /* support free on NULL */
     dctx->customMem.customFree(dctx->customMem.opaque, dctx);
     return 0;   /* reserved as a potential error code in the future */
 }
index 245c57d686517b43d3754bbc94cbe161b065a09a..21d56c5e003f628e8ca3ee5a0abeed03e9e6fa0b 100644 (file)
@@ -57,9 +57,5 @@ $(ZLIBWRAPPER_PATH)/zstdTurnedOn_zlibwrapper.o: $(ZLIBWRAPPER_PATH)/zstd_zlibwra
        $(CC) $(CFLAGS) -DZWRAP_USE_ZSTD=1 -I. -c -o $@ $(ZLIBWRAPPER_PATH)/zstd_zlibwrapper.c
 
 clean:
-       -$(RM) $(ZLIBWRAPPER_PATH)/*.o
-       -$(RM) $(EXAMPLE_PATH)/*.o
-       -$(RM) *.o
-       -$(RM) *.exe
-       -$(RM) foo.gz
-
+       -$(RM) $(ZLIBWRAPPER_PATH)/*.o $(EXAMPLE_PATH)/*.o *.o *.exe foo.gz example example_d example_zstd
+       @echo Cleaning completed