Skip to content

Commit 95509e1

Browse files
committed
patch 7.4.1746
Problem: Memory leak in Perl. Solution: Decrement the reference count. Add a test. (Damien)
1 parent 5d98c9d commit 95509e1

3 files changed

Lines changed: 26 additions & 5 deletions

File tree

src/if_perl.xs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -844,6 +844,7 @@ I32 cur_val(IV iv, SV *sv)
844844
else
845845
rv = newBUFrv(newSV(0), curbuf);
846846
sv_setsv(sv, rv);
847+
SvREFCNT_dec(SvRV(rv));
847848
return 0;
848849
}
849850
#endif /* !PROTO */

src/testdir/test_perl.vim

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ fu <SID>catch_peval(expr)
3434
endtry
3535
call assert_true(0, 'no exception for `perleval("'.a:expr.'")`')
3636
return ''
37-
endf
37+
endfunc
3838

3939
function Test_perleval()
4040
call assert_false(perleval('undef'))
@@ -73,7 +73,7 @@ function Test_perleval()
7373

7474
call assert_equal('*VIM', perleval('"*VIM"'))
7575
call assert_true(perleval('\\0') =~ 'SCALAR(0x\x\+)')
76-
endf
76+
endfunc
7777

7878
function Test_perldo()
7979
sp __TEST__
@@ -82,7 +82,7 @@ function Test_perldo()
8282
1
8383
call assert_false(search('\Cperl'))
8484
bw!
85-
endf
85+
endfunc
8686

8787
function Test_VIM_package()
8888
perl VIM::DoCommand('let l:var = "foo"')
@@ -91,7 +91,7 @@ function Test_VIM_package()
9191
set noet
9292
perl VIM::SetOption('et')
9393
call assert_true(&et)
94-
endf
94+
endfunc
9595

9696
function Test_stdio()
9797
redir =>l:out
@@ -102,4 +102,22 @@ function Test_stdio()
102102
EOF
103103
redir END
104104
call assert_equal(['&VIM::Msg', 'STDOUT', 'STDERR'], split(l:out, "\n"))
105-
endf
105+
endfunc
106+
107+
function Test_SvREFCNT()
108+
new t
109+
perl <<--perl
110+
my ($b, $w);
111+
$b = $curbuf for 0 .. 10;
112+
$w = $curwin for 0 .. 10;
113+
VIM::DoCommand('bw! t');
114+
if (exists &Internals::SvREFCNT) {
115+
my $cb = Internals::SvREFCNT($$b);
116+
my $cw = Internals::SvREFCNT($$w);
117+
VIM::Eval("assert_equal(2, $cb)");
118+
VIM::Eval("assert_equal(2, $cw)");
119+
}
120+
VIM::Eval("assert_false($$b)");
121+
VIM::Eval("assert_false($$w)");
122+
--perl
123+
endfunc

src/version.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -748,6 +748,8 @@ static char *(features[]) =
748748

749749
static int included_patches[] =
750750
{ /* Add new patch number below this line */
751+
/**/
752+
1746,
751753
/**/
752754
1745,
753755
/**/

0 commit comments

Comments
 (0)