fixed: deallocation of structures in case of error in ZBUFF_createCCtx and ZBUFF_createDCtx
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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 */
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user