From 11b11f08f56ba77707e2a160cc36648b6f14effb Mon Sep 17 00:00:00 2001
From: Japin Li <japinli@hotmail.com>
Date: Wed, 20 Jul 2022 14:12:53 +0800
Subject: [PATCH v5 1/1] fix the memory leak in psql describe

---
 src/bin/psql/describe.c | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/src/bin/psql/describe.c b/src/bin/psql/describe.c
index c7ff55fbd7..32a18becba 100644
--- a/src/bin/psql/describe.c
+++ b/src/bin/psql/describe.c
@@ -3441,7 +3441,10 @@ describeRoles(const char *pattern, bool verbose, bool showSystem)
 
 	res = PSQLexec(buf.data);
 	if (!res)
+	{
+		termPQExpBuffer(&buf);
 		return false;
+	}
 
 	nrows = PQntuples(res);
 	attr = pg_malloc0((nrows + 1) * sizeof(*attr));
@@ -4800,7 +4803,10 @@ describeOneTSParser(const char *oid, const char *nspname, const char *prsname)
 	res = PSQLexec(buf.data);
 	termPQExpBuffer(&buf);
 	if (!res)
+	{
+		termPQExpBuffer(&title);
 		return false;
+	}
 
 	myopt.nullPrint = NULL;
 	if (nspname)
-- 
2.17.1

