Commit 9fafa413 authored by Robert Haas's avatar Robert Haas

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 9da0cc35 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.
parent 3785f7ee
...@@ -86,6 +86,7 @@ ...@@ -86,6 +86,7 @@
#include "storage/buffile.h" #include "storage/buffile.h"
#include "utils/builtins.h" #include "utils/builtins.h"
#include "utils/logtape.h" #include "utils/logtape.h"
#include "utils/memdebug.h"
#include "utils/memutils.h" #include "utils/memutils.h"
/* /*
...@@ -874,6 +875,17 @@ LogicalTapeFreeze(LogicalTapeSet *lts, int tapenum, TapeShare *share) ...@@ -874,6 +875,17 @@ LogicalTapeFreeze(LogicalTapeSet *lts, int tapenum, TapeShare *share)
*/ */
if (lt->dirty) if (lt->dirty)
{ {
/*
* As long as we've filled the buffer at least once, its contents are
* entirely defined from valgrind's point of view, even though
* contents beyond the current end point may be stale. But it's
* possible - at least in the case of a parallel sort - to sort such
* small amount of data that we do not fill the buffer even once. Tell
* valgrind that its contents are defined, so it doesn't bleat.
*/
VALGRIND_MAKE_MEM_DEFINED(lt->buffer + lt->nbytes,
lt->buffer_size - lt->nbytes);
TapeBlockSetNBytes(lt->buffer, lt->nbytes); TapeBlockSetNBytes(lt->buffer, lt->nbytes);
ltsWriteBlock(lts, lt->curBlockNumber, (void *) lt->buffer); ltsWriteBlock(lts, lt->curBlockNumber, (void *) lt->buffer);
lt->writing = false; lt->writing = false;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment