Re: memory-related bugs - Mailing list pgsql-hackers

From Tom Lane
Subject Re: memory-related bugs
Date
Msg-id 26254.1299951869@sss.pgh.pa.us
Whole thread Raw
In response to memory-related bugs  (Noah Misch <noah@leadboat.com>)
Responses Re: memory-related bugs
List pgsql-hackers
Noah Misch <noah@leadboat.com> writes:
> A suitably-instrumented run of "make installcheck-world" under valgrind turned
> up a handful of memory-related bugs:

Hmm, interesting work, but I don't think I believe in the necessity for
this kluge:

> +     else if (attributeName != &(att->attname))
> +         namestrcpy(&(att->attname), attributeName);

The rules against overlapping memcpy/strcpy's source and destination are
meant to cover the case of partial overlap; I find it hard to imagine an
implementation that will mess up when the source and destination are
identical.  If we did think it was important to avoid this situation I
would rather find another way, like modifying the caller.  Likewise
the other changes to avoid no-op memcpy's do not appear to me to be
bugs, though possibly they might save enough cycles to be worth doing
anyway.

> !     stats->attrtype = (Form_pg_type) palloc(sizeof(FormData_pg_type));
> !     memcpy(stats->attrtype, GETSTRUCT(typtuple), sizeof(FormData_pg_type));
> ...
> !     stats->attrtype = (Form_pg_type) palloc(TYPE_FIXED_PART_SIZE);
> !     memcpy(stats->attrtype, GETSTRUCT(typtuple), TYPE_FIXED_PART_SIZE);

I wonder whether we should instead fix this by copying the correct tuple
length.
        regards, tom lane


pgsql-hackers by date:

Previous
From: Tom Lane
Date:
Subject: Collations versus user-defined functions
Next
From: Martijn van Oosterhout
Date:
Subject: Re: Collations versus user-defined functions