diff options
| author | Noah Misch <noah@leadboat.com> | 2013-06-26 20:00:08 -0400 |
|---|---|---|
| committer | Noah Misch <noah@leadboat.com> | 2013-06-26 20:22:25 -0400 |
| commit | 19085116eeecfde0a3fc1611eaffccc35bcec204 (patch) | |
| tree | 415f6a5e558f735c107cda09a81709898ee1f028 /src/backend/access | |
| parent | a855148a29b786b179308b3bd5c59fe5b67110d8 (diff) | |
Cooperate with the Valgrind instrumentation framework.
Valgrind "client requests" in aset.c and mcxt.c teach Valgrind and its
Memcheck tool about the PostgreSQL allocator. This makes Valgrind
roughly as sensitive to memory errors involving palloc chunks as it is
to memory errors involving malloc chunks. Further client requests in
PageAddItem() and printtup() verify that all bits being added to a
buffer page or furnished to an output function are predictably-defined.
Those tests catch failures of C-language functions to fully initialize
the bits of a Datum, which in turn stymie optimizations that rely on
_equalConst(). Define the USE_VALGRIND symbol in pg_config_manual.h to
enable these additions. An included "suppression file" silences nominal
errors we don't plan to fix.
Reviewed in earlier versions by Peter Geoghegan and Korry Douglas.
Diffstat (limited to 'src/backend/access')
| -rw-r--r-- | src/backend/access/common/printtup.c | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/src/backend/access/common/printtup.c b/src/backend/access/common/printtup.c index e87e6752b67..8daac9e4f5a 100644 --- a/src/backend/access/common/printtup.c +++ b/src/backend/access/common/printtup.c @@ -20,6 +20,7 @@ #include "libpq/pqformat.h" #include "tcop/pquery.h" #include "utils/lsyscache.h" +#include "utils/memdebug.h" static void printtup_startup(DestReceiver *self, int operation, @@ -324,9 +325,26 @@ printtup(TupleTableSlot *slot, DestReceiver *self) /* * If we have a toasted datum, forcibly detoast it here to avoid * memory leakage inside the type's output routine. + * + * Here we catch undefined bytes in tuples that are returned to the + * client without hitting disk; see comments at the related check in + * PageAddItem(). Whether to test before or after detoast is somewhat + * arbitrary, as is whether to test external/compressed data at all. + * Undefined bytes in the pre-toast datum will have triggered Valgrind + * errors in the compressor or toaster; any error detected here for + * such datums would indicate an (unlikely) bug in a type-independent + * facility. Therefore, this test is most useful for uncompressed, + * non-external datums. + * + * We don't presently bother checking non-varlena datums for undefined + * data. PageAddItem() does check them. */ if (thisState->typisvarlena) + { + VALGRIND_CHECK_MEM_IS_DEFINED(origattr, VARSIZE_ANY(origattr)); + attr = PointerGetDatum(PG_DETOAST_DATUM(origattr)); + } else attr = origattr; |
