[PATCH v1] fix potential memory leak in untransformRelOptions

Junwang Zhao <zhjwpku@gmail.com>

From: Junwang Zhao <zhjwpku@gmail.com>
To: PostgreSQL Hackers <pgsql-hackers@lists.postgresql.org>
Date: 2022-09-01T08:36:33Z
Lists: pgsql-hackers

Attachments

*TextDatumGetCString* calls palloc to alloc memory for the option
text datum, in some cases the the memory is allocated in
*TopTransactionContext*, this may cause memory leak for a long
running backend.
---
 src/backend/access/common/reloptions.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/src/backend/access/common/reloptions.c
b/src/backend/access/common/reloptions.c
index 609329bb21..6076677aef 100644
--- a/src/backend/access/common/reloptions.c
+++ b/src/backend/access/common/reloptions.c
@@ -1360,6 +1360,7 @@ untransformRelOptions(Datum options)
  val = (Node *) makeString(pstrdup(p));
  }
  result = lappend(result, makeDefElem(pstrdup(s), val, -1));
+ pfree(s);
  }

  return result;
-- 
2.33.0

-- 
Regards
Junwang Zhao

Commits

  1. Remove useless pstrdups in untransformRelOptions