Re: Server Programming in C: palloc() and pfree() - Mailing list pgsql-hackers

From Tom Lane
Subject Re: Server Programming in C: palloc() and pfree()
Date
Msg-id 5417.1139524324@sss.pgh.pa.us
Whole thread Raw
In response to Server Programming in C: palloc() and pfree()  (Rodrigo Hjort <rodrigo.hjort@gmail.com>)
List pgsql-hackers
Rodrigo Hjort <rodrigo.hjort@gmail.com> writes:
> I'm having some problems when using "pfree()" on functions in C.

I think your pfree is just the bearer of bad news, ie, it's the victim
of a memory clobber that you've already executed.  Take another look at
your string manipulation --- that strncpy followed by strcat in
particular looks pretty dangerous, because strncpy doesn't guarantee
a trailing null.

[ looks again... ]  Hmm, not to mention that you are overwriting the
input "str", which is bad enough in itself, but you are doing so with
a string longer than the original.
        regards, tom lane


pgsql-hackers by date:

Previous
From: Tom Lane
Date:
Subject: Re: PostgreSQL 8.0.6 crash
Next
From: "Mark Woodward"
Date:
Subject: Re: PostgreSQL 8.0.6 crash