[largeNbDicts] Second try at fixing decompression segfault to always create compressInstructions

Summary:
Freeing an uninitialized pointer is undefined behavior. This caused a segfault
when compiling the benchmark with Clang -O3 and benching decompression.

V2: always create compressInstructions but check if cctxParams is NULL before
setting CCtx params to avoid segfault.

Test Plan:
make and run
This commit is contained in:
Han Zhu 2022-07-20 16:01:32 -07:00
parent 466e13f722
commit 6255f994d3

View File

@ -582,6 +582,7 @@ compressInstructions createCompressInstructions(cdict_collection_t dictionaries,
compressInstructions ci; compressInstructions ci;
ci.cctx = ZSTD_createCCtx(); ci.cctx = ZSTD_createCCtx();
CONTROL(ci.cctx != NULL); CONTROL(ci.cctx != NULL);
if (cctxParams)
ZSTD_CCtx_setParametersUsingCCtxParams(ci.cctx, cctxParams); ZSTD_CCtx_setParametersUsingCCtxParams(ci.cctx, cctxParams);
ci.nbDicts = dictionaries.nbCDict; ci.nbDicts = dictionaries.nbCDict;
ci.dictNb = 0; ci.dictNb = 0;
@ -697,9 +698,8 @@ static int benchMem(slice_collection_t dstBlocks, slice_collection_t srcBlocks,
BMK_createTimedFnState(total_time_ms, ms_per_round); BMK_createTimedFnState(total_time_ms, ms_per_round);
decompressInstructions di = createDecompressInstructions(ddictionaries); decompressInstructions di = createDecompressInstructions(ddictionaries);
compressInstructions ci; compressInstructions ci =
if (benchCompression) createCompressInstructions(cdictionaries, cctxParams);
ci = createCompressInstructions(cdictionaries, cctxParams);
void* payload = benchCompression ? (void*)&ci : (void*)&di; void* payload = benchCompression ? (void*)&ci : (void*)&di;
BMK_benchParams_t const bp = { BMK_benchParams_t const bp = {
.benchFn = benchCompression ? compress : decompress, .benchFn = benchCompression ? compress : decompress,