]> git.ipfire.org Git - thirdparty/zstd.git/commitdiff
erase existence of a buffer when it's sent out of the pool 873/head
authorYann Collet <cyan@fb.com>
Fri, 29 Sep 2017 23:27:47 +0000 (16:27 -0700)
committerYann Collet <cyan@fb.com>
Fri, 29 Sep 2017 23:27:47 +0000 (16:27 -0700)
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

index 03871421cb0336cc82260f519b7e8dc82cfd7c7f..2d4fe2573d53c9927f7cddd616d1fb1da2d385d9 100644 (file)
@@ -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);