]> granicus.if.org Git - postgresql/commitdiff
Fix two valgrind issues in slab allocator.
authorAndres Freund <andres@anarazel.de>
Tue, 4 Apr 2017 21:26:42 +0000 (14:26 -0700)
committerAndres Freund <andres@anarazel.de>
Tue, 4 Apr 2017 21:26:42 +0000 (14:26 -0700)
During allocation VALGRIND_MAKE_MEM_DEFINED was called with a pointer
as size. That kind of works, but makes valgrind exceedingly slow for
workloads involving the slab allocator.

Secondly there was an access to memory marked as unreachable within
SlabCheck(). Fix that too.

Author: Tomas Vondra
Discussion: https://postgr.es/m/a6543b6d-6015-99b1-63ef-3ed55a76a730@2ndquadrant.com

src/backend/utils/mmgr/slab.c

index d6be4fe6603853fbb41b849f278fd22614dc994c..0fcfcb4c786e2b2f1046258470fbf0479f004ed5 100644 (file)
@@ -403,7 +403,7 @@ SlabAlloc(MemoryContext context, Size size)
         * Remove the chunk from the freelist head. The index of the next free
         * chunk is stored in the chunk itself.
         */
-       VALGRIND_MAKE_MEM_DEFINED(chunk, SlabChunkGetPointer(chunk));
+       VALGRIND_MAKE_MEM_DEFINED(SlabChunkGetPointer(chunk), sizeof(int32));
        block->firstFreeChunk = *(int32 *) SlabChunkGetPointer(chunk);
 
        Assert(block->firstFreeChunk >= 0);
@@ -725,6 +725,7 @@ SlabCheck(MemoryContext context)
 
                                /* read index of the next free chunk */
                                chunk = SlabBlockGetChunk(slab, block, idx);
+                               VALGRIND_MAKE_MEM_DEFINED(SlabChunkGetPointer(chunk), sizeof(int32));
                                idx = *(int32 *) SlabChunkGetPointer(chunk);
                        }