diff options
author | Yan Pashkovsky <yanp.bugz@gmail.com> | 2020-02-03 13:50:02 (GMT) |
---|---|---|
committer | Yan Pashkovsky <yanp.bugz@gmail.com> | 2020-02-03 13:50:02 (GMT) |
commit | 4cc9d863a3ef97b41979dbb119178ebe1df46dd1 (patch) | |
tree | 1fe168737fdaa8b7288498499aea557ccf061406 /lib | |
parent | 2553cd550b53532cc7d19831db520c9812cbb667 (diff) | |
download | lz4-4cc9d863a3ef97b41979dbb119178ebe1df46dd1.zip lz4-4cc9d863a3ef97b41979dbb119178ebe1df46dd1.tar.gz lz4-4cc9d863a3ef97b41979dbb119178ebe1df46dd1.tar.bz2 |
fix malloc handling
Diffstat (limited to 'lib')
-rw-r--r-- | lib/lz4hc.c | 5 |
1 files changed, 4 insertions, 1 deletions
diff --git a/lib/lz4hc.c b/lib/lz4hc.c index 8049840..b75514f 100644 --- a/lib/lz4hc.c +++ b/lib/lz4hc.c @@ -1290,7 +1290,7 @@ static int LZ4HC_compress_optimal ( LZ4HC_CCtx_internal* ctx, int retval = 0; #define TRAILING_LITERALS 3 #ifdef LZ4HC_HEAPMODE - LZ4HC_optimal_t* opt = (LZ4HC_optimal_t*)malloc(sizeof(LZ4HC_optimal_t) * (LZ4_OPT_NUM + TRAILING_LITERALS)); + LZ4HC_optimal_t* const opt = (LZ4HC_optimal_t*)malloc(sizeof(LZ4HC_optimal_t) * (LZ4_OPT_NUM + TRAILING_LITERALS)); #else LZ4HC_optimal_t opt[LZ4_OPT_NUM + TRAILING_LITERALS]; /* ~64 KB, which is a bit large for stack... */ #endif @@ -1305,6 +1305,9 @@ static int LZ4HC_compress_optimal ( LZ4HC_CCtx_internal* ctx, BYTE* oend = op + dstCapacity; /* init */ +#ifdef LZ4HC_HEAPMODE + if (opt == NULL) goto _return_label; +#endif DEBUGLOG(5, "LZ4HC_compress_optimal(dst=%p, dstCapa=%u)", dst, (unsigned)dstCapacity); *srcSizePtr = 0; if (limit == fillOutput) oend -= LASTLITERALS; /* Hack for support LZ4 format restriction */ |