Fix memory leak pointed out by Coverity.
authorTatsuo Ishii <ishii@sraoss.co.jp>
Wed, 2 Feb 2022 01:19:26 +0000 (10:19 +0900)
committerTatsuo Ishii <ishii@sraoss.co.jp>
Wed, 2 Feb 2022 01:20:51 +0000 (10:20 +0900)
Actually it's a false positive.

src/protocol/pool_process_query.c

index e75d9c68558a4f6b80d9b0a48792d457d06755ef..bf685de786c2f16467fba284b43ec4bf032e3a72 100644 (file)
@@ -1007,6 +1007,16 @@ ParameterStatus(POOL_CONNECTION * frontend, POOL_CONNECTION_POOL * backend)
                        if (IS_MASTER_NODE_ID(i))
                        {
                                len1 = len;
+                               /*
+                                * To suppress Coverity false positive warning.  Actually
+                                * being IS_MAIN_NODE_ID(i)) true only happens in a loop.  So
+                                * we don't need to worry about to leak memory previously
+                                * allocated in parambuf.  But Coverity is not smart enough
+                                * to realize it.
+                                */
+                               if (parambuf)
+                                       pfree(parambuf);
+
                                parambuf = palloc(len);
                                memcpy(parambuf, p, len);
                                pool_add_param(&CONNECTION(backend, i)->params, name, value);