| From: | tianbing <tian_bing_0531(at)163(dot)com> |
|---|---|
| To: | "Peter Smith" <smithpb2250(at)gmail(dot)com> |
| Cc: | "Shubham Khanna" <khannashubham1197(at)gmail(dot)com>, "vignesh C" <vignesh21(at)gmail(dot)com>, "Chao Li" <li(dot)evan(dot)chao(at)gmail(dot)com>, "Zhijie Hou (Fujitsu)" <houzj(dot)fnst(at)fujitsu(dot)com>, "Hayato Kuroda (Fujitsu)" <kuroda(dot)hayato(at)fujitsu(dot)com>, "PostgreSQL Hackers" <pgsql-hackers(at)lists(dot)postgresql(dot)org> |
| Subject: | Re:Re: Add support for specifying tables in pg_createsubscriber. |
| Date: | 2025-12-03 05:46:37 |
| Message-ID: | 3d33a85a.535b.19ae2bf9401.Coremail.tian_bing_0531@163.com |
| Views: | Whole Thread | Raw Message | Download mbox | Resend email |
| Thread: | |
| Lists: | pgsql-hackers |
Hi, Peter,
I have reviewed the v21 patch and noticed that there seems to be a memory leak.
+static bool
+check_publication_exists(PGconn *conn, const char *pubname, const char *dbname)
+{
+ PGresult *res;
+ bool exists;
+ char *query;
+
+ query = psprintf("SELECT 1 FROM pg_publication WHERE pubname = %s",
+ PQescapeLiteral(conn, pubname, strlen(pubname)));
+ res = PQexec(conn, query);
+
+ if (PQresultStatus(res) != PGRES_TUPLES_OK)
+ pg_fatal("could not check for publication \"%s\" in database \"%s\": %s",
+ pubname, dbname, PQerrorMessage(conn));
+
+ exists = (PQntuples(res) == 1);
+
+ PQclear(res);
+ pg_free(query);
+ return exists;
+}
The PQescapeLiteral() function through malloc to allocate memmory,and should be free by PQfreemem。
I suggest making the following modifications:
+ char *pub = PQescapeLiteral(conn, pubname, strlen(pubname);
+ query = psprintf("SELECT 1 FROM pg_publication WHERE pubname = %s", pub);
......
+ PQfreemem(pub);
Best Regards.
| From | Date | Subject | |
|---|---|---|---|
| Next Message | Michael Paquier | 2025-12-03 05:54:52 | Re: [Proposal] Adding callback support for custom statistics kinds |
| Previous Message | Amit Kapila | 2025-12-03 05:45:06 | Re: Allow GUC settings in CREATE SUBSCRIPTION CONNECTION to take effect |