From: Zefram Date: Sun, 11 Sep 2011 12:57:41 +0000 (+0100) Subject: avoid memory leak in toke_scan_str X-Git-Tag: 0.006007~5 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=08c39634f810a05a7c2f578aa619c4da53906ac5;p=p5sagit%2FDevel-Declare.git avoid memory leak in toke_scan_str --- diff --git a/Changes b/Changes index 706de85..ceded56 100644 --- a/Changes +++ b/Changes @@ -3,6 +3,7 @@ Changes for Devel-Declare - Depend on B::Hooks::OP::Check version 0.19, which fixes a serious bug in how it interacts with other modules that hook ops. - Detect and croak if unwanted reallocation occurs during toke_scan_str. + - Avoid memory leak in toke_scan_str. - Add MYMETA.{json,yml} to MANIFEST.SKIP and .gitignore. 0.006006 - 23 Aug 2011 diff --git a/Declare.xs b/Declare.xs index 41a991b..3f1728a 100644 --- a/Declare.xs +++ b/Declare.xs @@ -220,7 +220,7 @@ int dd_toke_scan_ident(pTHX_ int offset) { int dd_toke_scan_str(pTHX_ int offset) { char* old_pvx = SvPVX(PL_linestr); STRLEN remaining = sv_len(PL_linestr) - offset; - SV* line_copy = newSVsv(PL_linestr); + SV* line_copy = sv_2mortal(newSVsv(PL_linestr)); char* base_s = SvPVX(PL_linestr) + offset; char* s = scan_str(base_s, FALSE, FALSE); if(SvPVX(PL_linestr) != old_pvx) @@ -230,7 +230,6 @@ int dd_toke_scan_str(pTHX_ int offset) { int ret = (s - SvPVX(PL_linestr)) + remaining; sv_catsv(line_copy, PL_linestr); dd_set_linestr(aTHX_ SvPV_nolen(line_copy)); - SvREFCNT_dec(line_copy); return ret; } return s - base_s;