Re: memory-related bugs

From: Noah Misch <noah(at)leadboat(dot)com>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: pgsql-hackers(at)postgresql(dot)org
Subject: Re: memory-related bugs
Date: 2011-03-13 09:10:21
Message-ID: 20110313091021.GB29508@tornado.gateway.2wire.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On Sat, Mar 12, 2011 at 12:44:29PM -0500, Tom Lane wrote:
> Noah Misch <noah(at)leadboat(dot)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.

I also find it hard to imagine an implementation that needs these changes to
produce correct behavior. Avoiding undefined behavior has intrinsic value, but
perhaps we do get greater value from the existing code.

> > ! 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.

Seems like a step in the wrong direction. We only use typlen and typbyval
beyond the immediate context.

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Martijn van Oosterhout 2011-03-13 12:25:23 Re: Collations versus user-defined functions
Previous Message Noah Misch 2011-03-13 09:09:49 Re: memory-related bugs