1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56
|
Description: fix memory leak:
The decode and encode methods allocated a SV for the result, this SV is
passed to the process_utf8() function which may croak() if the CHECK flag
has FB_CROAK set.
Origin: upstream, 2.49 release
Bug: https://github.com/dankogai/p5-encode/issues/8
Bug-Debian: http://bugs.debian.org/702444
Author: Christian Hansen
Reviewed-by: gregor herrmann <gregoa@debian.org>
Last-Update: 2013-03-06
--- a/Encode.xs
+++ b/Encode.xs
@@ -440,7 +440,6 @@
if (src == &PL_sv_undef || SvROK(src)) src = sv_2mortal(newSV(0));
s = (U8 *) SvPV(src, slen);
e = (U8 *) SvEND(src);
- dst = newSV(slen>0?slen:1); /* newSV() abhors 0 -- inaba */
check = SvROK(check_sv) ? ENCODE_PERLQQ|ENCODE_LEAVE_SRC : SvIV(check_sv);
/*
* PerlIO check -- we assume the object is of PerlIO if renewed
@@ -471,6 +470,7 @@
}
}
+ dst = sv_2mortal(newSV(slen>0?slen:1)); /* newSV() abhors 0 -- inaba */
s = process_utf8(aTHX_ dst, s, e, check_sv, 0, strict_utf8(aTHX_ obj), renewed);
/* Clear out translated part of source unless asked not to */
@@ -482,7 +482,7 @@
SvCUR_set(src, slen);
}
SvUTF8_on(dst);
- ST(0) = sv_2mortal(dst);
+ ST(0) = dst;
XSRETURN(1);
}
@@ -504,7 +504,7 @@
if (src == &PL_sv_undef || SvROK(src)) src = sv_2mortal(newSV(0));
s = (U8 *) SvPV(src, slen);
e = (U8 *) SvEND(src);
- dst = newSV(slen>0?slen:1); /* newSV() abhors 0 -- inaba */
+ dst = sv_2mortal(newSV(slen>0?slen:1)); /* newSV() abhors 0 -- inaba */
if (SvUTF8(src)) {
/* Already encoded */
if (strict_utf8(aTHX_ obj)) {
@@ -543,7 +543,7 @@
}
SvPOK_only(dst);
SvUTF8_off(dst);
- ST(0) = sv_2mortal(dst);
+ ST(0) = dst;
XSRETURN(1);
}
|