Okay, here are the lines from valgrind after rebuilding with --enable-valgrind:
...
==17731== 244,800 bytes in 1,700 blocks are definitely lost in loss record 19 of 19
==17731== at 0x43B8405: malloc (vg_replace_malloc.c:149)
==17731== by 0x62B4C6A: PQmakeEmptyPGresult (in /opt/opt.CORE/postgresql-8.3.3/rhel4/lib/libpq.so.5.1)
==17731== by 0x62BE56A: pqParseInput3 (in /opt/opt.CORE/postgresql-8.3.3/rhel4/lib/libpq.so.5.1)
==17731== by 0x62B631F: PQgetResult (in /opt/opt.CORE/postgresql-8.3.3/rhel4/lib/libpq.so.5.1)
==17731== by 0x62B64B7: PQexecFinish (in /opt/opt.CORE/postgresql-8.3.3/rhel4/lib/libpq.so.5.1)
==17731== by 0x62542AF: writePgSQL (ompgsql.c:170)
==17731== by 0x6254353: doAction (ompgsql.c:203)
==17731== by 0x8072902: actionCallDoAction (action.c:429)
==17731== by 0x806CDF8: qAddDirect (queue.c:938)
==17731== by 0x806EEE4: queueEnqObj (queue.c:1015)
==17731== by 0x8072455: actionWriteToAction (action.c:570)
==17731== by 0x80725A3: actionCallAction (action.c:672)
==17731==
==17731== LEAK SUMMARY:
==17731== definitely lost: 244,800 bytes in 1,700 blocks.
==17731== possibly lost: 552 bytes in 4 blocks.
==17731== still reachable: 27,716 bytes in 172 blocks.
==17731== suppressed: 0 bytes in 0 blocks.
I looked at the code in ompgsql.c where it calls PQexec(). Apparently, the original author was not handling the returned pointer to the PGresult from the call. It needs a specific call to PQclear for each of the calls. The change needed is to wrap the PQexec calls with the PQclear() since the individual results are never examined anyway:
orig:
- Code: Select all
/* try insert */
PQexec(pData->f_hpgsql, (char*)psz);
if(PQstatus(pData->f_hpgsql) != CONNECTION_OK) {
/* error occured, try to re-init connection and retry */
closePgSQL(pData); /* close the current handle */
CHKiRet(initPgSQL(pData, 0)); /* try to re-open */
PQexec(pData->f_hpgsql, (char*)psz);
if(PQstatus(pData->f_hpgsql) != CONNECTION_OK) { /* re-try insert */
to:
- Code: Select all
/* try insert */
PQclear(PQexec(pData->f_hpgsql, (char*)psz));
if(PQstatus(pData->f_hpgsql) != CONNECTION_OK) {
/* error occured, try to re-init connection and retry */
closePgSQL(pData); /* close the current handle */
CHKiRet(initPgSQL(pData, 0)); /* try to re-open */
PQclear(PQexec(pData->f_hpgsql, (char*)psz));
if(PQstatus(pData->f_hpgsql) != CONNECTION_OK) { /* re-try insert */
The valgrind check of the resulting executable shows no memory leak. This change will need to be made to all rsyslog ompgsql.c files for their next point release.
Cheers,
Ken