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:19:26 +0000 (10:19 +0900)
Actually it's a false positive.

src/protocol/pool_process_query.c

index b996cd0a6a4b90878fccc0b78844cb36dcb1aa0d..9433fbb93606c611362d56e954315e4c007cb50f 100644 (file)
@@ -949,6 +949,16 @@ ParameterStatus(POOL_CONNECTION * frontend, POOL_CONNECTION_POOL * backend)
                                int     pos;
 
                                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);