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

Commitd25c2ee

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 parentfafec4c commitd25c2ee

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
@@ -966,6 +966,14 @@ pqGetErrorNotice2(PGconn *conn, bool isError)
966966
char*startp;
967967
char*splitp;
968968

969+
/*
970+
* If this is an error message, pre-emptively clear any incomplete query
971+
* result we may have. We'd just throw it away below anyway, and
972+
* releasing it before collecting the error might avoid out-of-memory.
973+
*/
974+
if (isError)
975+
pqClearAsyncResult(conn);
976+
969977
/*
970978
* Since the message might be pretty long, we create a temporary
971979
* PQExpBuffer rather than using conn->workBuffer. workBuffer is intended
@@ -1038,7 +1046,7 @@ pqGetErrorNotice2(PGconn *conn, bool isError)
10381046
*/
10391047
if (isError)
10401048
{
1041-
pqClearAsyncResult(conn);
1049+
pqClearAsyncResult(conn);/* redundant, but be safe */
10421050
conn->result=res;
10431051
resetPQExpBuffer(&conn->errorMessage);
10441052
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
@@ -879,6 +879,14 @@ pqGetErrorNotice3(PGconn *conn, bool isError)
879879
PQExpBufferDataworkBuf;
880880
charid;
881881

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

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp