From 82d8bd50b0d477204cabeb2a47e8b4e9f3bbbefe Mon Sep 17 00:00:00 2001 From: chenxiaobin19 <1025221611@qq.com> Date: Sat, 21 Sep 2024 11:40:34 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8Dlibpqwalreceiver=E8=8B=A5?= =?UTF-8?q?=E5=B9=B2=E5=86=85=E5=AD=98=E6=B3=84=E6=BC=8F=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/common/backend/nodes/copyfuncs.cpp | 2 ++ src/common/backend/nodes/equalfuncs.cpp | 2 ++ .../storage/replication/libpqwalreceiver.cpp | 20 ++++++++++++++++--- .../storage/replication/walreceiver.cpp | 5 ----- src/include/nodes/parsenodes.h | 1 + 5 files changed, 22 insertions(+), 8 deletions(-) diff --git a/src/common/backend/nodes/copyfuncs.cpp b/src/common/backend/nodes/copyfuncs.cpp index fbbbde7e2..79c885c59 100644 --- a/src/common/backend/nodes/copyfuncs.cpp +++ b/src/common/backend/nodes/copyfuncs.cpp @@ -5694,6 +5694,8 @@ static AlterFunctionStmt* _copyAlterFunctionStmt(const AlterFunctionStmt* from) COPY_SCALAR_FIELD(isProcedure); } + COPY_SCALAR_FIELD(noargs); + return newnode; } diff --git a/src/common/backend/nodes/equalfuncs.cpp b/src/common/backend/nodes/equalfuncs.cpp index 81c433b45..254f2e302 100644 --- a/src/common/backend/nodes/equalfuncs.cpp +++ b/src/common/backend/nodes/equalfuncs.cpp @@ -1624,6 +1624,8 @@ static bool _equalAlterFunctionStmt(const AlterFunctionStmt* a, const AlterFunct COMPARE_SCALAR_FIELD(isProcedure); } + COMPARE_SCALAR_FIELD(noargs); + return true; } diff --git a/src/gausskernel/storage/replication/libpqwalreceiver.cpp b/src/gausskernel/storage/replication/libpqwalreceiver.cpp index 10b1bf7f0..844ced328 100755 --- a/src/gausskernel/storage/replication/libpqwalreceiver.cpp +++ b/src/gausskernel/storage/replication/libpqwalreceiver.cpp @@ -269,12 +269,14 @@ void StartRemoteStreaming(const LibpqrcvConnectParam *options) appendStringInfo(&cmd, " %X/%X", (uint32)(options->startpoint >> 32), (uint32)(options->startpoint)); if (options->logical) { + char *pubnames_literal = NULL; appendStringInfoString(&cmd, " ("); appendStringInfo(&cmd, "proto_version '%u'", options->protoVersion); char *pubnames_str = stringlist_to_identifierstr(t_thrd.libwalreceiver_cxt.streamConn, options->publicationNames); - appendStringInfo(&cmd, ", publication_names %s", - PQescapeLiteral(t_thrd.libwalreceiver_cxt.streamConn, pubnames_str, strlen(pubnames_str))); + pubnames_literal = PQescapeLiteral(t_thrd.libwalreceiver_cxt.streamConn, pubnames_str, strlen(pubnames_str)); + appendStringInfo(&cmd, ", publication_names %s", pubnames_literal); + PQfreemem(pubnames_literal); pfree(pubnames_str); if (options->binary && PQserverVersion(t_thrd.libwalreceiver_cxt.streamConn) >= 90204) { @@ -1311,6 +1313,11 @@ void libpqrcv_disconnect(void) { PQfinish(t_thrd.libwalreceiver_cxt.streamConn); t_thrd.libwalreceiver_cxt.streamConn = NULL; + + if (t_thrd.libwalreceiver_cxt.recvBuf != NULL) { + PQfreemem(t_thrd.libwalreceiver_cxt.recvBuf); + t_thrd.libwalreceiver_cxt.recvBuf = NULL; + } } /* @@ -1709,13 +1716,20 @@ static char *stringlist_to_identifierstr(PGconn *conn, List *strings) foreach (lc, strings) { char *val = strVal(lfirst(lc)); + char *val_escaped = NULL; if (first) { first = false; } else { appendStringInfoChar(&res, ','); } - appendStringInfoString(&res, PQescapeIdentifier(conn, val, strlen(val))); + val_escaped = PQescapeIdentifier(conn, val, strlen(val)); + if (!val_escaped) { + free(res.data); + return NULL; + } + appendStringInfoString(&res, val_escaped); + PQfreemem(val_escaped); } return res.data; diff --git a/src/gausskernel/storage/replication/walreceiver.cpp b/src/gausskernel/storage/replication/walreceiver.cpp index 82ce0a062..051d0d360 100755 --- a/src/gausskernel/storage/replication/walreceiver.cpp +++ b/src/gausskernel/storage/replication/walreceiver.cpp @@ -1096,11 +1096,6 @@ static void WalRcvDie(int code, Datum arg) /* Wake up the startup process to notice promptly that we're gone */ WakeupRecovery(); - if (t_thrd.libwalreceiver_cxt.recvBuf != NULL) { - PQfreemem(t_thrd.libwalreceiver_cxt.recvBuf); - t_thrd.libwalreceiver_cxt.recvBuf = NULL; - } - if (t_thrd.libwalreceiver_cxt.decompressBuf != NULL) { pfree(t_thrd.libwalreceiver_cxt.decompressBuf); t_thrd.libwalreceiver_cxt.decompressBuf = NULL; diff --git a/src/include/nodes/parsenodes.h b/src/include/nodes/parsenodes.h index b6fff9b1f..c3ea16cc2 100755 --- a/src/include/nodes/parsenodes.h +++ b/src/include/nodes/parsenodes.h @@ -1410,6 +1410,7 @@ typedef struct AlterFunctionStmt { FuncWithArgs* func; /* name and args of function */ List* actions; /* list of DefElem */ bool isProcedure = false; + bool noargs; /* support alter function without args in dolphin */ } AlterFunctionStmt; enum CompileEntry {