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.




Reply via email to