From 1416bc0f07b266e4c682f44968af1745dcce064c Mon Sep 17 00:00:00 2001 From: Yann Collet Date: Fri, 29 Sep 2017 16:27:47 -0700 Subject: [PATCH] erase existence of a buffer when it's sent out of the pool In some complex scenario, the buffer would be freed because it's too large, another buffer would be allocated, but fail, trigger an error, and the general buffer pool would then be freed, where the definition of the already freed buffer would be found (beyond total index, but still), and freed again, resulting in double-free error. --- lib/compress/zstdmt_compress.c | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/compress/zstdmt_compress.c b/lib/compress/zstdmt_compress.c index 03871421..2d4fe257 100644 --- a/lib/compress/zstdmt_compress.c +++ b/lib/compress/zstdmt_compress.c @@ -155,6 +155,7 @@ static buffer_t ZSTDMT_getBuffer(ZSTDMT_bufferPool* bufPool) if (bufPool->nbBuffers) { /* try to use an existing buffer */ buffer_t const buf = bufPool->bTable[--(bufPool->nbBuffers)]; size_t const availBufferSize = buf.size; + bufPool->bTable[bufPool->nbBuffers] = g_nullBuffer; if ((availBufferSize >= bSize) & (availBufferSize <= 10*bSize)) { /* large enough, but not too much */ ZSTD_pthread_mutex_unlock(&bufPool->poolMutex);