Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
plperl: Fix memory leak in hek2cstr
authorAlvaro Herrera <alvherre@alvh.no-ip.org>
Mon, 17 Mar 2014 02:22:22 +0000 (23:22 -0300)
committerAlvaro Herrera <alvherre@alvh.no-ip.org>
Mon, 17 Mar 2014 02:22:22 +0000 (23:22 -0300)
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

index 930b9f04b8569e50787096dc72f3ca0b17cc0102..3bc4034b9419317601c752f24e24c0370bf069aa 100644 (file)
@@ -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;
 }
 
 /*