PQclear in ReportResultError to prevent memory leaks

pull/1109/head
Marco Slot 2017-01-10 02:18:01 +01:00
parent 31231ce196
commit ef326b202a
1 changed files with 47 additions and 34 deletions

View File

@ -124,6 +124,9 @@ ReportConnectionError(MultiConnection *connection, int elevel)
*/ */
void void
ReportResultError(MultiConnection *connection, PGresult *result, int elevel) ReportResultError(MultiConnection *connection, PGresult *result, int elevel)
{
/* we release PQresult when throwing an error because the caller can't */
PG_TRY();
{ {
char *sqlStateString = PQresultErrorField(result, PG_DIAG_SQLSTATE); char *sqlStateString = PQresultErrorField(result, PG_DIAG_SQLSTATE);
char *messagePrimary = PQresultErrorField(result, PG_DIAG_MESSAGE_PRIMARY); char *messagePrimary = PQresultErrorField(result, PG_DIAG_MESSAGE_PRIMARY);
@ -137,8 +140,11 @@ ReportResultError(MultiConnection *connection, PGresult *result, int elevel)
if (sqlStateString != NULL) if (sqlStateString != NULL)
{ {
sqlState = MAKE_SQLSTATE(sqlStateString[0], sqlStateString[1], sqlStateString[2], sqlState = MAKE_SQLSTATE(sqlStateString[0],
sqlStateString[3], sqlStateString[4]); sqlStateString[1],
sqlStateString[2],
sqlStateString[3],
sqlStateString[4]);
} }
/* /*
@ -166,6 +172,13 @@ ReportResultError(MultiConnection *connection, PGresult *result, int elevel)
errcontext("while executing command on %s:%d", errcontext("while executing command on %s:%d",
nodeName, nodePort))); nodeName, nodePort)));
} }
PG_CATCH();
{
PQclear(result);
PG_RE_THROW();
}
PG_END_TRY();
}
/* /*