Skip to content
Snippets Groups Projects
Commit f84997c7 authored by Alvaro Herrera's avatar Alvaro Herrera
Browse files

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
parent 8976360e
No related branches found
Tags
No related merge requests found
...@@ -303,6 +303,16 @@ static char *setlocale_perl(int category, char *locale); ...@@ -303,6 +303,16 @@ static char *setlocale_perl(int category, char *locale);
static char * static char *
hek2cstr(HE *he) 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 * 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 * 128..255 it's not, but perl will treat them as unicode code points if
...@@ -327,11 +337,17 @@ hek2cstr(HE *he) ...@@ -327,11 +337,17 @@ hek2cstr(HE *he)
* right thing * right thing
*------------------------- *-------------------------
*/ */
SV *sv = HeSVKEY_force(he);
sv = HeSVKEY_force(he);
if (HeUTF8(he)) if (HeUTF8(he))
SvUTF8_on(sv); SvUTF8_on(sv);
return sv2cstr(sv); ret = sv2cstr(sv);
/* free sv */
FREETMPS;
LEAVE;
return ret;
} }
/* /*
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment