Re: Compiler warnings with stringRelOpts (was WIP: Fast GiST index build) - Mailing list pgsql-hackers

From Tom Lane
Subject Re: Compiler warnings with stringRelOpts (was WIP: Fast GiST index build)
Date
Msg-id 27894.1312906576@sss.pgh.pa.us
Whole thread Raw
In response to Re: Compiler warnings with stringRelOpts (was WIP: Fast GiST index build)  (Heikki Linnakangas <heikki.linnakangas@enterprisedb.com>)
List pgsql-hackers
Heikki Linnakangas <heikki.linnakangas@enterprisedb.com> writes:
> On 09.08.2011 18:04, Alvaro Herrera wrote:
>> I think I vaguely remember that the reason for doing it this way is that
>> the copy into the relcache worked, i.e. if the originals went away,
>> there was no dangling pointer.  Did you test this?

> These strings are never freed, so I don't think it's possible to end up 
> with a dangling pointer.

Well, in that case the relevant question is whether we need to worry
about memory leaks due to multiple copies.

Personally I'm wondering why the function is strdup'ing the default
value at all.  In practice, wouldn't it practically always be a compile
time constant string?  Why create possible issues by designing the code
for a different use-case?  In particular, why not declare the default
value as "const char *" and specify that it's caller's responsibility
that it live forever if it's not just a constant string?
        regards, tom lane


pgsql-hackers by date:

Previous
From: Tom Lane
Date:
Subject: Re: Enforcing that all WAL has been replayed after restoring from backup
Next
From: Tom Lane
Date:
Subject: Re: plperl crash with Debian 6 (64 bit), pl/perlu, libwww and https