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

Commit 6082907

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 ae7d04a commit 6082907

File tree

1 file changed

+18
-2
lines changed

1 file changed

+18
-2
lines changed

src/pl/plperl/plperl.c

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -304,6 +304,16 @@ static char *setlocale_perl(int category, char *locale);
304304
static char *
305305
hek2cstr(HE *he)
306306
{
307+
char *ret;
308+
SV *sv;
309+
310+
/*
311+
* HeSVKEY_force will return a temporary mortal SV*, so we need to make
312+
* sure to free it with ENTER/SAVE/FREE/LEAVE
313+
*/
314+
ENTER;
315+
SAVETMPS;
316+
307317
/*-------------------------
308318
* Unfortunately, while HeUTF8 is true for most things > 256, for values
309319
* 128..255 it's not, but perl will treat them as unicode code points if
@@ -328,11 +338,17 @@ hek2cstr(HE *he)
328338
* right thing
329339
*-------------------------
330340
*/
331-
SV *sv = HeSVKEY_force(he);
332341

342+
sv = HeSVKEY_force(he);
333343
if (HeUTF8(he))
334344
SvUTF8_on(sv);
335-
return sv2cstr(sv);
345+
ret = sv2cstr(sv);
346+
347+
/* free sv */
348+
FREETMPS;
349+
LEAVE;
350+
351+
return ret;
336352
}
337353

338354
/*

0 commit comments

Comments
 (0)