Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitd014b38

Browse files
committed
In libpq, free any partial query result before collecting a server error.
We'd throw away the partial result anyway after parsing the error message.Throwing it away beforehand costs nothing and reduces the risk ofout-of-memory failure. Also, at least in systems that behave likeglibc/Linux, if the partial result was very large then the error PGresultwould get allocated at high heap addresses, preventing the heap storageused by the partial result from being released to the OS until the errorPGresult is freed.In psql >= 9.6, we hold onto the error PGresult until another error isreceived (for \errverbose), so that this behavior causes a seemingmemory leak to persist for awhile, as in a recent complaint fromDarafei Praliaskouski. This is a potential performance regression fromolder versions, justifying back-patching at least that far. But similarbehavior may occur in other client applications, so it seems worth justback-patching to all supported branches.Discussion:https://postgr.es/m/CAC8Q8tJ=7cOkPePyAbJE_Pf691t8nDFhJp0KZxHvnq_uicfyVg@mail.gmail.com
1 parent4013218 commitd014b38

File tree

2 files changed

+18
-2
lines changed

2 files changed

+18
-2
lines changed

‎src/interfaces/libpq/fe-protocol2.c

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -967,6 +967,14 @@ pqGetErrorNotice2(PGconn *conn, bool isError)
967967
char*startp;
968968
char*splitp;
969969

970+
/*
971+
* If this is an error message, pre-emptively clear any incomplete query
972+
* result we may have. We'd just throw it away below anyway, and
973+
* releasing it before collecting the error might avoid out-of-memory.
974+
*/
975+
if (isError)
976+
pqClearAsyncResult(conn);
977+
970978
/*
971979
* Since the message might be pretty long, we create a temporary
972980
* PQExpBuffer rather than using conn->workBuffer. workBuffer is intended
@@ -1039,7 +1047,7 @@ pqGetErrorNotice2(PGconn *conn, bool isError)
10391047
*/
10401048
if (isError)
10411049
{
1042-
pqClearAsyncResult(conn);
1050+
pqClearAsyncResult(conn);/* redundant, but be safe */
10431051
conn->result=res;
10441052
resetPQExpBuffer(&conn->errorMessage);
10451053
if (res&& !PQExpBufferDataBroken(workBuf)&&res->errMsg)

‎src/interfaces/libpq/fe-protocol3.c

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -880,6 +880,14 @@ pqGetErrorNotice3(PGconn *conn, bool isError)
880880
PQExpBufferDataworkBuf;
881881
charid;
882882

883+
/*
884+
* If this is an error message, pre-emptively clear any incomplete query
885+
* result we may have. We'd just throw it away below anyway, and
886+
* releasing it before collecting the error might avoid out-of-memory.
887+
*/
888+
if (isError)
889+
pqClearAsyncResult(conn);
890+
883891
/*
884892
* Since the fields might be pretty long, we create a temporary
885893
* PQExpBuffer rather than using conn->workBuffer. workBuffer is intended
@@ -944,7 +952,7 @@ pqGetErrorNotice3(PGconn *conn, bool isError)
944952
{
945953
if (res)
946954
res->errMsg=pqResultStrdup(res,workBuf.data);
947-
pqClearAsyncResult(conn);
955+
pqClearAsyncResult(conn);/* redundant, but be safe */
948956
conn->result=res;
949957
if (PQExpBufferDataBroken(workBuf))
950958
printfPQExpBuffer(&conn->errorMessage,

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp