postgres.git / summary / log / commit / refs
commit bd1154edec5484390d7dcd05d12287ccc81c30e8
Author: Alvaro Herrera <alvherre@alvh.no-ip.org>
Date: Mon Mar 17 02:22:21 2014 +0000
plperl: Fix memory leak in hek2cstr
Backpatch all the way back to 9.1, where it was introduced by commit
50d89d42.
Reported by Sergey Burladyan in #9223
Author: Alex Hunsaker
src/pl/plperl/plperl.c | 20 ++++++++++++++++++--
1 file changed, 18 insertions(+), 2 deletions(-)
diff --git a/src/pl/plperl/plperl.c b/src/pl/plperl/plperl.c
index e91b71e7779..7bc29a6b324 100644
--- a/src/pl/plperl/plperl.c
+++ b/src/pl/plperl/plperl.c
@@ -308,6 +308,16 @@ static char *setlocale_perl(int category, char *locale);
static char *
hek2cstr(HE *he)
{
+ char *ret;
+ SV *sv;
+
+ /*
+ * HeSVKEY_force will return a temporary mortal SV*, so we need to make
+ * sure to free it with ENTER/SAVE/FREE/LEAVE
+ */
+ ENTER;
+ SAVETMPS;
+
/*-------------------------
* Unfortunately, while HeUTF8 is true for most things > 256, for values
* 128..255 it's not, but perl will treat them as unicode code points if
@@ -332,11 +342,17 @@ hek2cstr(HE *he)
* right thing
*-------------------------
*/
- SV *sv = HeSVKEY_force(he);
+ sv = HeSVKEY_force(he);
if (HeUTF8(he))
SvUTF8_on(sv);
- return sv2cstr(sv);
+ ret = sv2cstr(sv);
+
+ /* free sv */
+ FREETMPS;
+ LEAVE;
+
+ return ret;
}
/*
[parent: 0268d21e5d3c]