Search Postgresql Archives

Re: when to use pfree?

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Ron Peterson <ron.peterson@xxxxxxxxxxxxxx> 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


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [Postgresql Jobs]     [Postgresql Admin]     [Postgresql Performance]     [Linux Clusters]     [PHP Home]     [PHP on Windows]     [Kernel Newbies]     [PHP Classes]     [PHP Books]     [PHP Databases]     [Postgresql & PHP]     [Yosemite]
  Powered by Linux