Skip to content

Commit 117d73a

Browse files
committed
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.
1 parent 7a6676d commit 117d73a

File tree

2 files changed

+10
-5
lines changed

2 files changed

+10
-5
lines changed

src/bin/pg_dump/pg_dump.c

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
* by PostgreSQL
1313
*
1414
* IDENTIFICATION
15-
* $PostgreSQL: pgsql/src/bin/pg_dump/pg_dump.c,v 1.434 2006/05/26 23:48:54 momjian Exp $
15+
* $PostgreSQL: pgsql/src/bin/pg_dump/pg_dump.c,v 1.435 2006/05/28 17:23:29 alvherre Exp $
1616
*
1717
*-------------------------------------------------------------------------
1818
*/
@@ -1445,16 +1445,15 @@ dumpStdStrings(Archive *AH)
14451445

14461446
check_sql_result(res, g_conn, qry->data, PGRES_TUPLES_OK);
14471447

1448-
PQclear(res);
1449-
14501448
resetPQExpBuffer(qry);
14511449

14521450
std_strings = (strcmp(PQgetvalue(res, 0, 0), "on") == 0);
14531451
appendPQExpBuffer(qry, "SET standard_conforming_strings = ");
14541452
appendStringLiteral(qry, PQgetvalue(res, 0, 0), true, !std_strings);
14551453
appendPQExpBuffer(qry, ";\n");
14561454
puts(PQgetvalue(res, 0, 0));
1457-
1455+
1456+
PQclear(res);
14581457
}
14591458

14601459
ArchiveEntry(AH, nilCatalogId, createDumpId(),

src/interfaces/libpq/fe-exec.c

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $PostgreSQL: pgsql/src/interfaces/libpq/fe-exec.c,v 1.184 2006/05/23 22:13:19 momjian Exp $
11+
* $PostgreSQL: pgsql/src/interfaces/libpq/fe-exec.c,v 1.185 2006/05/28 17:23:29 alvherre Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -364,6 +364,12 @@ PQclear(PGresult *res)
364364
if (res->tuples)
365365
free(res->tuples);
366366

367+
/* zero out the pointer fields to catch programming errors */
368+
res->attDescs = NULL;
369+
res->tuples = NULL;
370+
res->errFields = NULL;
371+
/* res->curBlock was zeroed out earlier */
372+
367373
/* Free the PGresult structure itself */
368374
free(res);
369375
}

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy