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)
In fact ,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 test_able ");
res =PQexec(conn,acQryBuf);
if ( PQresultStatus(res)!= PGRES_COMMAND_OK){
printf("\n %s\n",PQresultErrorMessage(res));
PQclear(res);
return false;
}
PQclear(res);
return true;
}
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兆,雅虎电邮自助扩容!