Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit bd1154e

Browse files
committed
plperl: Fix memory leak in hek2cstr
Backpatch all the way back to 9.1, where it was introduced by commit 50d89d4. Reported by Sergey Burladyan in #9223 Author: Alex Hunsaker
1 parent 0268d21 commit bd1154e

File tree

1 file changed

+18
-2
lines changed

1 file changed

+18
-2
lines changed

src/pl/plperl/plperl.c

+18-2
Original file line numberDiff line numberDiff line change
@@ -308,6 +308,16 @@ static char *setlocale_perl(int category, char *locale);
308308
static char *
309309
hek2cstr(HE *he)
310310
{
311+
char *ret;
312+
SV *sv;
313+
314+
/*
315+
* HeSVKEY_force will return a temporary mortal SV*, so we need to make
316+
* sure to free it with ENTER/SAVE/FREE/LEAVE
317+
*/
318+
ENTER;
319+
SAVETMPS;
320+
311321
/*-------------------------
312322
* Unfortunately, while HeUTF8 is true for most things > 256, for values
313323
* 128..255 it's not, but perl will treat them as unicode code points if
@@ -332,11 +342,17 @@ hek2cstr(HE *he)
332342
* right thing
333343
*-------------------------
334344
*/
335-
SV *sv = HeSVKEY_force(he);
336345

346+
sv = HeSVKEY_force(he);
337347
if (HeUTF8(he))
338348
SvUTF8_on(sv);
339-
return sv2cstr(sv);
349+
ret = sv2cstr(sv);
350+
351+
/* free sv */
352+
FREETMPS;
353+
LEAVE;
354+
355+
return ret;
340356
}
341357

342358
/*

0 commit comments

Comments
 (0)