[PATCH v1] fix potential memory leak in untransformRelOptions

From: Junwang Zhao <zhjwpku(at)gmail(dot)com>
To: PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Subject: [PATCH v1] fix potential memory leak in untransformRelOptions
Date: 2022-09-01 08:36:33
Message-ID: CAEG8a3Lz7M7tZ-7KR7243X+xHPiJVTm_9eZZvP5rfkH1bCWAJw@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

*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

Attachment Content-Type Size
0001-fix-potential-memory-leak-in-untransformRelOptions.patch application/octet-stream 942 bytes

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Dave Page 2022-09-01 08:46:59 Re: Tracking last scan time
Previous Message Junwang Zhao 2022-09-01 08:18:49 use NoLock instead of the magic number 0