Hi, hackers!

There is a memory leak in functions check_application_name() and check_cluster_name().
Functions are located in src/backend/commands/variable.c

The leak can be triggered using SQL command: SET application_name=new_name; You can run pgbench with this command for a long time by passing this command in file via '-f' flag.

regards,
Tofig
From a801d03c57819d3de181967d72260cb42bbcf6a3 Mon Sep 17 00:00:00 2001
From: Tofig Aliev <t.al...@postgrespro.ru>
Date: Fri, 6 Dec 2024 14:58:38 +0700
Subject: [PATCH] Fix tiny memory leaks

Memory for (*newval) allocated earlier
in the parse_and_validate_value() method.
Since this method re-allocates memory,
it is necessary to free the previously allocated memory.
---
 src/backend/commands/variable.c | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/src/backend/commands/variable.c b/src/backend/commands/variable.c
index 0ecff94d0e..2c8059e8d8 100644
--- a/src/backend/commands/variable.c
+++ b/src/backend/commands/variable.c
@@ -1092,6 +1092,8 @@ check_application_name(char **newval, void **extra, GucSource source)
 		return false;
 	}
 
+	guc_free(*newval);
+
 	pfree(clean);
 	*newval = ret;
 	return true;
@@ -1128,6 +1130,8 @@ check_cluster_name(char **newval, void **extra, GucSource source)
 		return false;
 	}
 
+	guc_free(*newval);
+
 	pfree(clean);
 	*newval = ret;
 	return true;
-- 
2.43.0

Reply via email to