Fix new memory leaks in libpq
authorAlvaro Herrera <alvherre@alvh.no-ip.org>
Sun, 21 Mar 2021 17:55:27 +0000 (14:55 -0300)
committerAlvaro Herrera <alvherre@alvh.no-ip.org>
Sun, 21 Mar 2021 17:55:27 +0000 (14:55 -0300)
My oversight in commit 9aa491abbf07.

Per coverity.

src/interfaces/libpq/fe-exec.c

index f3443708a6bd13e374889d54812f08d42f651957..f143b8b7fb83242089a4d8e512aa9d1b77279c08 100644 (file)
@@ -1299,10 +1299,6 @@ PQsendQueryInternal(PGconn *conn, const char *query, bool newQuery)
        if (!PQsendQueryStart(conn, newQuery))
                return 0;
 
-       entry = pqAllocCmdQueueEntry(conn);
-       if (entry == NULL)
-               return 0;                               /* error msg already set */
-
        /* check the argument */
        if (!query)
        {
@@ -1311,6 +1307,10 @@ PQsendQueryInternal(PGconn *conn, const char *query, bool newQuery)
                return 0;
        }
 
+       entry = pqAllocCmdQueueEntry(conn);
+       if (entry == NULL)
+               return 0;                               /* error msg already set */
+
        /* Send the query message(s) */
        if (conn->pipelineStatus == PQ_PIPELINE_OFF)
        {
@@ -1320,6 +1320,7 @@ PQsendQueryInternal(PGconn *conn, const char *query, bool newQuery)
                        pqPutMsgEnd(conn) < 0)
                {
                        /* error message should be set up already */
+                       pqRecycleCmdQueueEntry(conn, entry);
                        return 0;
                }