single a suggestion - Mailing list pgsql-bugs

From pgsql-bugs@postgresql.org
Subject single a suggestion
Date
Msg-id 200102060611.f166BVg14244@hub.org
Whole thread Raw
List pgsql-bugs
KADIR ROJAS (ridak22@tutopia.com) reports a bug with a severity of 3
The lower the number the more severe it is.

Short Description
single a suggestion

Long Description
Hello from Panama.

Working with pglib library, I discovered
something, that could become a problem for the developers if they don't
have strict control over what they are doing.  It is the PQclear()
function.

When we call this function to release the assigned
resources, and it has been called previously, it is not registered,
causing a segmentation fault in the programs. I think that we could avoid some headaches to our programs, if we give a
morerobust form to the function,  
making a safer PQclear function.

At the time of declaring the pointer to the structure it
must be initialized in NULL (PQresult * res=NULL).
This could guarantee that it won't accidentally release
nonassigned resources. If we make this change the library itself
would be able to have a registry of the calls to the function pqclear,
so, the programmers wouldn't have to worry about this little issue and
concentrate on other subjects. I'd like to know what do you think of this.

thanks a lot for your attention.
KJRC


Sample Code
/* Secure PQclear */
void SPQclear(PQresult **res)
{
 if(*res)
  {
   PQclear(*res);
   *res = NULL;
  }
 return;
}

void main(void)
{
 PQresult *res=NULL;

  .
  .
  .
  SPQclear(&res);
  .
  .
  .
}

No file was uploaded with this report

pgsql-bugs by date:

Previous
From: Tatsuo Ishii
Date:
Subject: Re: [HACKERS] Re: syslog logging setup broken?
Next
From: Piers Scannell
Date:
Subject: RE: single a suggestion