Re: Server Programming in C: palloc() and pfree()

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Rodrigo Hjort <rodrigo(dot)hjort(at)gmail(dot)com>
Cc: pgsql-hackers(at)postgresql(dot)org
Subject: Re: Server Programming in C: palloc() and pfree()
Date: 2006-02-09 22:32:04
Message-ID: 5417.1139524324@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Rodrigo Hjort <rodrigo(dot)hjort(at)gmail(dot)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

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Mark Woodward 2006-02-09 23:53:18 Re: PostgreSQL 8.0.6 crash
Previous Message Tom Lane 2006-02-09 22:04:38 Re: PostgreSQL 8.0.6 crash