From 1e31f1d25cda257b11d62e8700ed650dca1bbe54 Mon Sep 17 00:00:00 2001 From: Yann Collet Date: Wed, 30 Sep 2020 22:51:17 -0700 Subject: fix bad init scenario --- lib/lz4hc.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/lib/lz4hc.c b/lib/lz4hc.c index 28b91f7..cd802d8 100644 --- a/lib/lz4hc.c +++ b/lib/lz4hc.c @@ -981,9 +981,11 @@ int LZ4_compress_HC_destSize(void* state, const char* source, char* dest, int* s /* allocation */ LZ4_streamHC_t* LZ4_createStreamHC(void) { - LZ4_streamHC_t* state = (LZ4_streamHC_t*)ALLOC(sizeof(LZ4_streamHC_t)); - if (state==NULL) return NULL; - state = LZ4_initStreamHC(state, sizeof(*state)); /* full initialization, malloc'ed buffer can be full of garbage */ + LZ4_streamHC_t* const state = (LZ4_streamHC_t*)ALLOC(sizeof(LZ4_streamHC_t)); + if (LZ4_initStreamHC(state, sizeof(*state)) == NULL) { + free(state); + return NULL; + } return state; } -- cgit v0.12