From: | Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> |
---|---|
To: | Ron Peterson <ron(dot)peterson(at)yellowbank(dot)com> |
Cc: | pgsql-general(at)postgresql(dot)org |
Subject: | Re: when to use pfree? |
Date: | 2006-11-07 14:53:27 |
Message-ID: | 9813.1162911207@sss.pgh.pa.us |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-general |
Ron Peterson <ron(dot)peterson(at)yellowbank(dot)com> writes:
> char*
> tp2cp_palloc( char* stringp, const text* textp ) {
> int len;
> len = VARSIZE(textp) - VARHDRSZ;
> stringp = (char*)palloc( len + 1 );
> if( ! memcpy( stringp, VARDATA(textp), len ) ) { return NULL; }
> if( ! memset( stringp + len, '\0', 1 ) ) { return NULL; }
> return stringp;
> }
That's simply bizarre coding style. stringp should be a local in
tp2cp_palloc, not a passed parameter that you ignore the value of.
> Which I call like
> otherfunc() {
> char* rd;
> if( ! tp2cp_palloc( rd, rand_dev ) )
> ...
The above does not cause rd to become set in otherfunc().
Had you been using a reasonable set of compiler flags, the compiler
would have warned you that rd was uninitialized in otherfunc().
regards, tom lane
From | Date | Subject | |
---|---|---|---|
Next Message | TJ O'Donnell | 2006-11-07 15:30:58 | Re: R and postgres |
Previous Message | Ron Peterson | 2006-11-07 13:55:31 | Re: when to use pfree? |