Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 9fafa41

Browse files
committed
Avoid valgrind complaint about write() of uninitalized bytes.
LogicalTapeFreeze() may write out its first block when it is dirty but not full, and then immediately read the first block back in from its BufFile as a BLCKSZ-width block. This can only occur in rare cases where very few tuples were written out, which is currently only possible with parallel external tuplesorts. To avoid valgrind complaints, tell it to treat the tail of logtape.c's buffer as defined. Commit 9da0cc3 exposed this problem but did not create it. LogicalTapeFreeze() has always tended to write out some amount of garbage bytes, but previously never wrote less than one block of data in total, so the problem was masked. Per buildfarm members lousyjack and skink. Peter Geoghegan, based on a suggestion from Tom Lane and me. Some comment revisions by me.
1 parent 3785f7e commit 9fafa41

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

src/backend/utils/sort/logtape.c

+12
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@
8686
#include "storage/buffile.h"
8787
#include "utils/builtins.h"
8888
#include "utils/logtape.h"
89+
#include "utils/memdebug.h"
8990
#include "utils/memutils.h"
9091

9192
/*
@@ -874,6 +875,17 @@ LogicalTapeFreeze(LogicalTapeSet *lts, int tapenum, TapeShare *share)
874875
*/
875876
if (lt->dirty)
876877
{
878+
/*
879+
* As long as we've filled the buffer at least once, its contents are
880+
* entirely defined from valgrind's point of view, even though
881+
* contents beyond the current end point may be stale. But it's
882+
* possible - at least in the case of a parallel sort - to sort such
883+
* small amount of data that we do not fill the buffer even once. Tell
884+
* valgrind that its contents are defined, so it doesn't bleat.
885+
*/
886+
VALGRIND_MAKE_MEM_DEFINED(lt->buffer + lt->nbytes,
887+
lt->buffer_size - lt->nbytes);
888+
877889
TapeBlockSetNBytes(lt->buffer, lt->nbytes);
878890
ltsWriteBlock(lts, lt->curBlockNumber, (void *) lt->buffer);
879891
lt->writing = false;

0 commit comments

Comments
 (0)