Don't call PQclear until the struct is really no longer going to be used.
Per Coverity bug #304. Thanks to Martijn van Oosterhout for reporting it. Zero out the pointer fields of PGresult so that these mistakes are more easily catched, per discussion.
This commit is contained in:
parent
7a6676d9df
commit
117d73a9e7
@ -12,7 +12,7 @@
|
|||||||
* by PostgreSQL
|
* by PostgreSQL
|
||||||
*
|
*
|
||||||
* IDENTIFICATION
|
* IDENTIFICATION
|
||||||
* $PostgreSQL: pgsql/src/bin/pg_dump/pg_dump.c,v 1.434 2006/05/26 23:48:54 momjian Exp $
|
* $PostgreSQL: pgsql/src/bin/pg_dump/pg_dump.c,v 1.435 2006/05/28 17:23:29 alvherre Exp $
|
||||||
*
|
*
|
||||||
*-------------------------------------------------------------------------
|
*-------------------------------------------------------------------------
|
||||||
*/
|
*/
|
||||||
@ -1445,8 +1445,6 @@ dumpStdStrings(Archive *AH)
|
|||||||
|
|
||||||
check_sql_result(res, g_conn, qry->data, PGRES_TUPLES_OK);
|
check_sql_result(res, g_conn, qry->data, PGRES_TUPLES_OK);
|
||||||
|
|
||||||
PQclear(res);
|
|
||||||
|
|
||||||
resetPQExpBuffer(qry);
|
resetPQExpBuffer(qry);
|
||||||
|
|
||||||
std_strings = (strcmp(PQgetvalue(res, 0, 0), "on") == 0);
|
std_strings = (strcmp(PQgetvalue(res, 0, 0), "on") == 0);
|
||||||
@ -1455,6 +1453,7 @@ dumpStdStrings(Archive *AH)
|
|||||||
appendPQExpBuffer(qry, ";\n");
|
appendPQExpBuffer(qry, ";\n");
|
||||||
puts(PQgetvalue(res, 0, 0));
|
puts(PQgetvalue(res, 0, 0));
|
||||||
|
|
||||||
|
PQclear(res);
|
||||||
}
|
}
|
||||||
|
|
||||||
ArchiveEntry(AH, nilCatalogId, createDumpId(),
|
ArchiveEntry(AH, nilCatalogId, createDumpId(),
|
||||||
|
@ -8,7 +8,7 @@
|
|||||||
*
|
*
|
||||||
*
|
*
|
||||||
* IDENTIFICATION
|
* IDENTIFICATION
|
||||||
* $PostgreSQL: pgsql/src/interfaces/libpq/fe-exec.c,v 1.184 2006/05/23 22:13:19 momjian Exp $
|
* $PostgreSQL: pgsql/src/interfaces/libpq/fe-exec.c,v 1.185 2006/05/28 17:23:29 alvherre Exp $
|
||||||
*
|
*
|
||||||
*-------------------------------------------------------------------------
|
*-------------------------------------------------------------------------
|
||||||
*/
|
*/
|
||||||
@ -364,6 +364,12 @@ PQclear(PGresult *res)
|
|||||||
if (res->tuples)
|
if (res->tuples)
|
||||||
free(res->tuples);
|
free(res->tuples);
|
||||||
|
|
||||||
|
/* zero out the pointer fields to catch programming errors */
|
||||||
|
res->attDescs = NULL;
|
||||||
|
res->tuples = NULL;
|
||||||
|
res->errFields = NULL;
|
||||||
|
/* res->curBlock was zeroed out earlier */
|
||||||
|
|
||||||
/* Free the PGresult structure itself */
|
/* Free the PGresult structure itself */
|
||||||
free(res);
|
free(res);
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user