diff options
author | Alvaro Herrera <alvherre@alvh.no-ip.org> | 2014-03-16 23:22:22 -0300 |
---|---|---|
committer | Alvaro Herrera <alvherre@alvh.no-ip.org> | 2014-03-16 23:22:22 -0300 |
commit | ba5946e8696e9629e77cc1e9c2c8bc722798a0a0 (patch) | |
tree | 82e470c457b563c96de299b3e557b719b2ac202d /src | |
parent | 3205d6b24e60eb7e7d2749b9447d5df98a6d84b9 (diff) | |
download | postgresql-ba5946e8696e9629e77cc1e9c2c8bc722798a0a0.tar.gz postgresql-ba5946e8696e9629e77cc1e9c2c8bc722798a0a0.zip |
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
Diffstat (limited to 'src')
-rw-r--r-- | src/pl/plperl/plperl.c | 20 |
1 files changed, 18 insertions, 2 deletions
diff --git a/src/pl/plperl/plperl.c b/src/pl/plperl/plperl.c index 49d50c44c36..4318eb8c86b 100644 --- a/src/pl/plperl/plperl.c +++ b/src/pl/plperl/plperl.c @@ -304,6 +304,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 @@ -328,11 +338,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; } /* |