ensure zlibwrapper uses ZSTD_malloc() and ZSTD_free()
which is compatible with { NULL, NULL, NULL }
This commit is contained in:
parent
b877e834b1
commit
dcb7535352
@ -61,7 +61,7 @@ void* ZSTD_calloc(size_t size, ZSTD_customMem customMem)
|
|||||||
{
|
{
|
||||||
if (customMem.customAlloc) {
|
if (customMem.customAlloc) {
|
||||||
/* calloc implemented as malloc+memset;
|
/* calloc implemented as malloc+memset;
|
||||||
* not as efficient, but our best guess for custom malloc */
|
* not as efficient as calloc, but next best guess for custom malloc */
|
||||||
void* const ptr = customMem.customAlloc(customMem.opaque, size);
|
void* const ptr = customMem.customAlloc(customMem.opaque, size);
|
||||||
memset(ptr, 0, size);
|
memset(ptr, 0, size);
|
||||||
return ptr;
|
return ptr;
|
||||||
|
@ -17,7 +17,7 @@
|
|||||||
#include "zstd_zlibwrapper.h"
|
#include "zstd_zlibwrapper.h"
|
||||||
#define ZSTD_STATIC_LINKING_ONLY /* ZSTD_MAGICNUMBER */
|
#define ZSTD_STATIC_LINKING_ONLY /* ZSTD_MAGICNUMBER */
|
||||||
#include "zstd.h"
|
#include "zstd.h"
|
||||||
#include "zstd_internal.h" /* defaultCustomMem */
|
#include "zstd_internal.h" /* ZSTD_malloc, ZSTD_free */
|
||||||
|
|
||||||
|
|
||||||
#define Z_INFLATE_SYNC 8
|
#define Z_INFLATE_SYNC 8
|
||||||
@ -100,7 +100,7 @@ size_t ZWRAP_freeCCtx(ZWRAP_CCtx* zwc)
|
|||||||
{
|
{
|
||||||
if (zwc==NULL) return 0; /* support free on NULL */
|
if (zwc==NULL) return 0; /* support free on NULL */
|
||||||
if (zwc->zbc) ZSTD_freeCStream(zwc->zbc);
|
if (zwc->zbc) ZSTD_freeCStream(zwc->zbc);
|
||||||
zwc->customMem.customFree(zwc->customMem.opaque, zwc);
|
ZSTD_free(zwc, zwc->customMem);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -472,8 +472,8 @@ size_t ZWRAP_freeDCtx(ZWRAP_DCtx* zwd)
|
|||||||
{
|
{
|
||||||
if (zwd==NULL) return 0; /* support free on null */
|
if (zwd==NULL) return 0; /* support free on null */
|
||||||
if (zwd->zbd) ZSTD_freeDStream(zwd->zbd);
|
if (zwd->zbd) ZSTD_freeDStream(zwd->zbd);
|
||||||
if (zwd->version) zwd->customMem.customFree(zwd->customMem.opaque, zwd->version);
|
ZSTD_free(zwd->version, zwd->customMem);
|
||||||
zwd->customMem.customFree(zwd->customMem.opaque, zwd);
|
ZSTD_free(zwd, zwd->customMem);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -505,22 +505,21 @@ ZEXTERN int ZEXPORT z_inflateInit_ OF((z_streamp strm,
|
|||||||
return inflateInit(strm);
|
return inflateInit(strm);
|
||||||
}
|
}
|
||||||
|
|
||||||
{
|
{ ZWRAP_DCtx* zwd = ZWRAP_createDCtx(strm);
|
||||||
ZWRAP_DCtx* zwd = ZWRAP_createDCtx(strm);
|
LOG_WRAPPERD("- inflateInit\n");
|
||||||
LOG_WRAPPERD("- inflateInit\n");
|
if (zwd == NULL) return ZWRAPD_finishWithError(zwd, strm, 0);
|
||||||
if (zwd == NULL) return ZWRAPD_finishWithError(zwd, strm, 0);
|
|
||||||
|
|
||||||
zwd->version = zwd->customMem.customAlloc(zwd->customMem.opaque, strlen(version) + 1);
|
zwd->version = ZSTD_malloc(strlen(version)+1, zwd->customMem);
|
||||||
if (zwd->version == NULL) return ZWRAPD_finishWithError(zwd, strm, 0);
|
if (zwd->version == NULL) return ZWRAPD_finishWithError(zwd, strm, 0);
|
||||||
strcpy(zwd->version, version);
|
strcpy(zwd->version, version);
|
||||||
|
|
||||||
zwd->stream_size = stream_size;
|
zwd->stream_size = stream_size;
|
||||||
zwd->totalInBytes = 0;
|
zwd->totalInBytes = 0;
|
||||||
strm->state = (struct internal_state*) zwd; /* use state which in not used by user */
|
strm->state = (struct internal_state*) zwd; /* use state which in not used by user */
|
||||||
strm->total_in = 0;
|
strm->total_in = 0;
|
||||||
strm->total_out = 0;
|
strm->total_out = 0;
|
||||||
strm->reserved = ZWRAP_UNKNOWN_STREAM; /* mark as unknown steam */
|
strm->reserved = ZWRAP_UNKNOWN_STREAM; /* mark as unknown steam */
|
||||||
strm->adler = 0;
|
strm->adler = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
return Z_OK;
|
return Z_OK;
|
||||||
@ -534,15 +533,14 @@ ZEXTERN int ZEXPORT z_inflateInit2_ OF((z_streamp strm, int windowBits,
|
|||||||
return inflateInit2_(strm, windowBits, version, stream_size);
|
return inflateInit2_(strm, windowBits, version, stream_size);
|
||||||
}
|
}
|
||||||
|
|
||||||
{
|
{ int ret = z_inflateInit_ (strm, version, stream_size);
|
||||||
int ret = z_inflateInit_ (strm, version, stream_size);
|
LOG_WRAPPERD("- inflateInit2 windowBits=%d\n", windowBits);
|
||||||
LOG_WRAPPERD("- inflateInit2 windowBits=%d\n", windowBits);
|
if (ret == Z_OK) {
|
||||||
if (ret == Z_OK) {
|
ZWRAP_DCtx* const zwd = (ZWRAP_DCtx*)strm->state;
|
||||||
ZWRAP_DCtx* zwd = (ZWRAP_DCtx*)strm->state;
|
if (zwd == NULL) return Z_STREAM_ERROR;
|
||||||
if (zwd == NULL) return Z_STREAM_ERROR;
|
zwd->windowBits = windowBits;
|
||||||
zwd->windowBits = windowBits;
|
}
|
||||||
}
|
return ret;
|
||||||
return ret;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -552,7 +550,7 @@ int ZWRAP_inflateReset_keepDict(z_streamp strm)
|
|||||||
if (g_ZWRAPdecompressionType == ZWRAP_FORCE_ZLIB || !strm->reserved)
|
if (g_ZWRAPdecompressionType == ZWRAP_FORCE_ZLIB || !strm->reserved)
|
||||||
return inflateReset(strm);
|
return inflateReset(strm);
|
||||||
|
|
||||||
{ ZWRAP_DCtx* zwd = (ZWRAP_DCtx*) strm->state;
|
{ ZWRAP_DCtx* const zwd = (ZWRAP_DCtx*) strm->state;
|
||||||
if (zwd == NULL) return Z_STREAM_ERROR;
|
if (zwd == NULL) return Z_STREAM_ERROR;
|
||||||
ZWRAP_initDCtx(zwd);
|
ZWRAP_initDCtx(zwd);
|
||||||
zwd->decompState = ZWRAP_useReset;
|
zwd->decompState = ZWRAP_useReset;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user