From 33b22e4ef2d1906c8ee2fd35eb5444cb19d53527 Mon Sep 17 00:00:00 2001 From: Diego Fronza Date: Fri, 6 Aug 2021 15:35:14 -0400 Subject: [PATCH] PG-203: Fix memory leak. The query_txt variable is allocated at the beginning of the pg_stat_monitor_internal() function and released at the end, but an extra malloc call to allocate it was added within an internal loop in the funcion, thus allocating memory for every loop iteration, without releasing the memory in the loop. The query_txt variable can be reused inside the loop body, so this commit removes the redundant declaration of query_txt from inside the loop, which also fixes the leak. --- pg_stat_monitor.c | 1 - 1 file changed, 1 deletion(-) diff --git a/pg_stat_monitor.c b/pg_stat_monitor.c index 6f651a9..c8dc638 100644 --- a/pg_stat_monitor.c +++ b/pg_stat_monitor.c @@ -1546,7 +1546,6 @@ pg_stat_monitor_internal(FunctionCallInfo fcinfo, uint64 planid = entry->key.planid; uint64 appid = entry->key.appid; unsigned char *buf = pgss_qbuf[bucketid]; - char *query_txt = (char*) malloc(PGSM_QUERY_MAX_LEN); #if PG_VERSION_NUM < 140000 bool is_allowed_role = is_member_of_role(GetUserId(), DEFAULT_ROLE_READ_ALL_STATS); #else