fixed: deallocation of structures in case of error in ZBUFF_createCCtx and ZBUFF_createDCtx
This commit is contained in:
parent
f040be9850
commit
3640396b1a
@ -118,6 +118,7 @@ ZBUFF_CCtx* ZBUFF_createCCtx_advanced(ZSTD_customMem customMem)
|
|||||||
memset(zbc, 0, sizeof(ZBUFF_CCtx));
|
memset(zbc, 0, sizeof(ZBUFF_CCtx));
|
||||||
memcpy(&zbc->customMem, &customMem, sizeof(ZSTD_customMem));
|
memcpy(&zbc->customMem, &customMem, sizeof(ZSTD_customMem));
|
||||||
zbc->zc = ZSTD_createCCtx_advanced(customMem);
|
zbc->zc = ZSTD_createCCtx_advanced(customMem);
|
||||||
|
if (zbc->zc == NULL) { ZBUFF_freeCCtx(zbc); return NULL; }
|
||||||
return zbc;
|
return zbc;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -125,8 +126,8 @@ size_t ZBUFF_freeCCtx(ZBUFF_CCtx* zbc)
|
|||||||
{
|
{
|
||||||
if (zbc==NULL) return 0; /* support free on NULL */
|
if (zbc==NULL) return 0; /* support free on NULL */
|
||||||
ZSTD_freeCCtx(zbc->zc);
|
ZSTD_freeCCtx(zbc->zc);
|
||||||
zbc->customMem.customFree(zbc->customMem.opaque, zbc->inBuff);
|
if (zbc->inBuff) zbc->customMem.customFree(zbc->customMem.opaque, zbc->inBuff);
|
||||||
zbc->customMem.customFree(zbc->customMem.opaque, zbc->outBuff);
|
if (zbc->outBuff) zbc->customMem.customFree(zbc->customMem.opaque, zbc->outBuff);
|
||||||
zbc->customMem.customFree(zbc->customMem.opaque, zbc);
|
zbc->customMem.customFree(zbc->customMem.opaque, zbc);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -143,7 +143,8 @@ ZSTD_CCtx* ZSTD_createCCtx_advanced(ZSTD_customMem customMem)
|
|||||||
|
|
||||||
size_t ZSTD_freeCCtx(ZSTD_CCtx* cctx)
|
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);
|
cctx->customMem.customFree(cctx->customMem.opaque, cctx);
|
||||||
return 0; /* reserved as a potential error code in the future */
|
return 0; /* reserved as a potential error code in the future */
|
||||||
}
|
}
|
||||||
|
@ -106,6 +106,7 @@ ZBUFF_DCtx* ZBUFF_createDCtx_advanced(ZSTD_customMem customMem)
|
|||||||
memset(zbd, 0, sizeof(ZBUFF_DCtx));
|
memset(zbd, 0, sizeof(ZBUFF_DCtx));
|
||||||
memcpy(&zbd->customMem, &customMem, sizeof(ZSTD_customMem));
|
memcpy(&zbd->customMem, &customMem, sizeof(ZSTD_customMem));
|
||||||
zbd->zd = ZSTD_createDCtx_advanced(customMem);
|
zbd->zd = ZSTD_createDCtx_advanced(customMem);
|
||||||
|
if (zbd->zd == NULL) { ZBUFF_freeDCtx(zbd); return NULL; }
|
||||||
zbd->stage = ZBUFFds_init;
|
zbd->stage = ZBUFFds_init;
|
||||||
return zbd;
|
return zbd;
|
||||||
}
|
}
|
||||||
@ -114,8 +115,8 @@ size_t ZBUFF_freeDCtx(ZBUFF_DCtx* zbd)
|
|||||||
{
|
{
|
||||||
if (zbd==NULL) return 0; /* support free on null */
|
if (zbd==NULL) return 0; /* support free on null */
|
||||||
ZSTD_freeDCtx(zbd->zd);
|
ZSTD_freeDCtx(zbd->zd);
|
||||||
zbd->customMem.customFree(zbd->customMem.opaque, zbd->inBuff);
|
if (zbd->inBuff) zbd->customMem.customFree(zbd->customMem.opaque, zbd->inBuff);
|
||||||
zbd->customMem.customFree(zbd->customMem.opaque, zbd->outBuff);
|
if (zbd->outBuff) zbd->customMem.customFree(zbd->customMem.opaque, zbd->outBuff);
|
||||||
zbd->customMem.customFree(zbd->customMem.opaque, zbd);
|
zbd->customMem.customFree(zbd->customMem.opaque, zbd);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -172,6 +172,7 @@ ZSTD_DCtx* ZSTD_createDCtx(void)
|
|||||||
|
|
||||||
size_t ZSTD_freeDCtx(ZSTD_DCtx* dctx)
|
size_t ZSTD_freeDCtx(ZSTD_DCtx* dctx)
|
||||||
{
|
{
|
||||||
|
if (dctx==NULL) return 0; /* support free on NULL */
|
||||||
dctx->customMem.customFree(dctx->customMem.opaque, dctx);
|
dctx->customMem.customFree(dctx->customMem.opaque, dctx);
|
||||||
return 0; /* reserved as a potential error code in the future */
|
return 0; /* reserved as a potential error code in the future */
|
||||||
}
|
}
|
||||||
|
@ -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
|
$(CC) $(CFLAGS) -DZWRAP_USE_ZSTD=1 -I. -c -o $@ $(ZLIBWRAPPER_PATH)/zstd_zlibwrapper.c
|
||||||
|
|
||||||
clean:
|
clean:
|
||||||
-$(RM) $(ZLIBWRAPPER_PATH)/*.o
|
-$(RM) $(ZLIBWRAPPER_PATH)/*.o $(EXAMPLE_PATH)/*.o *.o *.exe foo.gz example example_d example_zstd
|
||||||
-$(RM) $(EXAMPLE_PATH)/*.o
|
@echo Cleaning completed
|
||||||
-$(RM) *.o
|
|
||||||
-$(RM) *.exe
|
|
||||||
-$(RM) foo.gz
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user