diff --git a/src/bin/pg_dump/pg_dump.c b/src/bin/pg_dump/pg_dump.c
index 950d47a44cb383f8396e4fe62bf3dd0eb29a5c61..a32af2846ac7ec65462ee97fa4fec79a85b1efd8 100644
--- a/src/bin/pg_dump/pg_dump.c
+++ b/src/bin/pg_dump/pg_dump.c
@@ -12,7 +12,7 @@
  *	by PostgreSQL
  *
  * 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);
 
-		PQclear(res);
-
 		resetPQExpBuffer(qry);
 
 		std_strings = (strcmp(PQgetvalue(res, 0, 0), "on") == 0);
@@ -1454,7 +1452,8 @@ dumpStdStrings(Archive *AH)
 		appendStringLiteral(qry, PQgetvalue(res, 0, 0), true, !std_strings);
 		appendPQExpBuffer(qry, ";\n");
 		puts(PQgetvalue(res, 0, 0));
-		
+
+		PQclear(res);
 	}
 	
 	ArchiveEntry(AH, nilCatalogId, createDumpId(),
diff --git a/src/interfaces/libpq/fe-exec.c b/src/interfaces/libpq/fe-exec.c
index 7b999c853304cb11393e1a78f6f841abf98e197e..71ba05fbca6e16935c6d1ee6ee8852b2cdf33b31 100644
--- a/src/interfaces/libpq/fe-exec.c
+++ b/src/interfaces/libpq/fe-exec.c
@@ -8,7 +8,7 @@
  *
  *
  * 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)
 		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(res);
 }