Re: memory leak of PQmakeEmptyPGresult?? - Mailing list pgsql-general

From Ann
Subject Re: memory leak of PQmakeEmptyPGresult??
Date
Msg-id 20041013032603.64174.qmail@web14308.mail.yahoo.com
Whole thread Raw
In response to memory leak of PQmakeEmptyPGresult??  (xiaoling he <he629@yahoo.com.cn>)
Responses Re: memory leak of PQmakeEmptyPGresult??  (Gaetano Mendola <mendola@bigfoot.com>)
List pgsql-general
I found the reason of this question and fixed the bug :))

xiaoling he <he629@yahoo.com.cn> wrote:
I try to detect potential memory management bugs of my program with valgrind. (PostgreSQL is at version 8.0 beta2. Operating System is Red Hat Enterprise Linux 3. Valgrind is at version 2.2.0.)
 
  After Program terminated, Valgrind reports a memory lost error information as follows:
==13524== 208 bytes in 2 blocks are definitely lost in loss record 4 of 12
==13524==    at 0x1B903D1C: malloc (vg_replace_malloc.c:131)
==13524==    by 0x1B95C8B2: PQmakeEmptyPGresult (in /usr/lib/libpq.so.3.0)
==13524==    by 0x1B95D14A: (within /usr/lib/libpq.so.3.0)
==13524==    by 0x1B95D963: PQgetResult (in /usr/lib/libpq.so.3.0)
  
    I never call PQmakeEmptyPGresult and PQgetResult function in my program!
 
   Then i searched information about PQmakeEmptyPGresult:
  “PQmakeEmptyPGresult Constructs an empty PGresult object with the given status.it is libpq’s internal routine to allocate and initialize an empty PGresult object. It is exported because some applications find it useful to generate result objects (particularly objects with error status)themselves. If conn is not NULL and status indicates an error, the connection’s current error message is copied into the PGresult. Note that PQclear should eventually be called on the object, just as with a PGresult returned by libpq itself. ”
 
  It seems some connection errors happened at the time I do some query or update operations on database.
 
     Now I was puzzled, because program runs normally and returns correct result every time. And I am sure I called PQclear()
after everytime called PQexec().
 
  There is a example of my program:
Bool bTest(void)
{
  PGresult *res;
  char acQryBuf[200];
 sprintf(acQryBuf, "%s", "select count(*) from testable ");
 res =PQexec(conn,acQryBuf);
   if ( PQresultStatus(res)!= PGRES_COMMAND_OK){  
  printf("\n %s\n",PQresultErrorMessage(res));
       PQclear(res);
      return false; 
   }
 PQclear(res);
 return true;
}
 
If PQclear() don't clear PGresult successfully, there will be some memory leaks.....Is it right? Why PQclear ()  run unsuccessfully evrytime?
 
Would that have anything to do with it?  Any other ideas of things to try?
Thanks!
     Ann
2004.10.12 pm 17:00



Do You Yahoo!?
150万曲MP3疯狂搜,带您闯入音乐殿堂
美女明星应有尽有,搜遍美图、艳图和酷图
1G就是1000兆,雅虎电邮自助扩容!



Do You Yahoo!?
150万曲MP3疯狂搜,带您闯入音乐殿堂
美女明星应有尽有,搜遍美图、艳图和酷图
1G就是1000兆,雅虎电邮自助扩容!

pgsql-general by date:

Previous
From: Mike Mascari
Date:
Subject: Re: Change primary key in Postgres 7.3?
Next
From: Michael Fuhr
Date:
Subject: Proposal: GRANT cascade to implicit sequences