aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/interfaces/libpq/fe-protocol2.c10
-rw-r--r--src/interfaces/libpq/fe-protocol3.c10
2 files changed, 18 insertions, 2 deletions
diff --git a/src/interfaces/libpq/fe-protocol2.c b/src/interfaces/libpq/fe-protocol2.c
index a58f701e18b..2bc7e6e8c7c 100644
--- a/src/interfaces/libpq/fe-protocol2.c
+++ b/src/interfaces/libpq/fe-protocol2.c
@@ -968,6 +968,14 @@ pqGetErrorNotice2(PGconn *conn, bool isError)
char *splitp;
/*
+ * If this is an error message, pre-emptively clear any incomplete query
+ * result we may have. We'd just throw it away below anyway, and
+ * releasing it before collecting the error might avoid out-of-memory.
+ */
+ if (isError)
+ pqClearAsyncResult(conn);
+
+ /*
* Since the message might be pretty long, we create a temporary
* PQExpBuffer rather than using conn->workBuffer. workBuffer is intended
* for stuff that is expected to be short.
@@ -1039,7 +1047,7 @@ pqGetErrorNotice2(PGconn *conn, bool isError)
*/
if (isError)
{
- pqClearAsyncResult(conn);
+ pqClearAsyncResult(conn); /* redundant, but be safe */
conn->result = res;
resetPQExpBuffer(&conn->errorMessage);
if (res && !PQExpBufferDataBroken(workBuf) && res->errMsg)
diff --git a/src/interfaces/libpq/fe-protocol3.c b/src/interfaces/libpq/fe-protocol3.c
index a484fe80a15..51055be88d7 100644
--- a/src/interfaces/libpq/fe-protocol3.c
+++ b/src/interfaces/libpq/fe-protocol3.c
@@ -881,6 +881,14 @@ pqGetErrorNotice3(PGconn *conn, bool isError)
char id;
/*
+ * If this is an error message, pre-emptively clear any incomplete query
+ * result we may have. We'd just throw it away below anyway, and
+ * releasing it before collecting the error might avoid out-of-memory.
+ */
+ if (isError)
+ pqClearAsyncResult(conn);
+
+ /*
* Since the fields might be pretty long, we create a temporary
* PQExpBuffer rather than using conn->workBuffer. workBuffer is intended
* for stuff that is expected to be short. We shouldn't use
@@ -944,7 +952,7 @@ pqGetErrorNotice3(PGconn *conn, bool isError)
{
if (res)
res->errMsg = pqResultStrdup(res, workBuf.data);
- pqClearAsyncResult(conn);
+ pqClearAsyncResult(conn); /* redundant, but be safe */
conn->result = res;
if (PQExpBufferDataBroken(workBuf))
printfPQExpBuffer(&conn->errorMessage,