Stop Perl_newSVpvn_share() potentially leaking the return result from
Nicholas Clark [Tue, 11 Apr 2006 16:17:13 +0000 (16:17 +0000)]
bytes_from_utf8().

p4raw-id: //depot/perl@27766

sv.c

diff --git a/sv.c b/sv.c
index de8f973..02e83a1 100644 (file)
--- a/sv.c
+++ b/sv.c
@@ -6990,6 +6990,8 @@ Perl_newSVpvn_share(pTHX_ const char *src, I32 len, U32 hash)
     dVAR;
     register SV *sv;
     bool is_utf8 = FALSE;
+    const char *const orig_src = src;
+
     if (len < 0) {
        STRLEN tmplen = -len;
         is_utf8 = TRUE;
@@ -7009,6 +7011,8 @@ Perl_newSVpvn_share(pTHX_ const char *src, I32 len, U32 hash)
     SvPOK_on(sv);
     if (is_utf8)
         SvUTF8_on(sv);
+    if (src != orig_src)
+       Safefree(src);
     return sv;
 }