Mercurial > vim
changeset 8919:240ad5a78199 v7.4.1746
commit https://github.com/vim/vim/commit/95509e18f8806046eeee27482c77666bbec515da
Author: Bram Moolenaar <Bram@vim.org>
Date: Fri Apr 15 21:16:11 2016 +0200
patch 7.4.1746
Problem: Memory leak in Perl.
Solution: Decrement the reference count. Add a test. (Damien)
author | Christian Brabandt <cb@256bit.org> |
---|---|
date | Fri, 15 Apr 2016 21:30:06 +0200 |
parents | e838dc987c93 |
children | 32a663a03f3d |
files | src/if_perl.xs src/testdir/test_perl.vim src/version.c |
diffstat | 3 files changed, 26 insertions(+), 5 deletions(-) [+] |
line wrap: on
line diff
--- a/src/if_perl.xs +++ b/src/if_perl.xs @@ -844,6 +844,7 @@ I32 cur_val(IV iv, SV *sv) else rv = newBUFrv(newSV(0), curbuf); sv_setsv(sv, rv); + SvREFCNT_dec(SvRV(rv)); return 0; } #endif /* !PROTO */
--- a/src/testdir/test_perl.vim +++ b/src/testdir/test_perl.vim @@ -34,7 +34,7 @@ fu <SID>catch_peval(expr) endtry call assert_true(0, 'no exception for `perleval("'.a:expr.'")`') return '' -endf +endfunc function Test_perleval() call assert_false(perleval('undef')) @@ -73,7 +73,7 @@ function Test_perleval() call assert_equal('*VIM', perleval('"*VIM"')) call assert_true(perleval('\\0') =~ 'SCALAR(0x\x\+)') -endf +endfunc function Test_perldo() sp __TEST__ @@ -82,7 +82,7 @@ function Test_perldo() 1 call assert_false(search('\Cperl')) bw! -endf +endfunc function Test_VIM_package() perl VIM::DoCommand('let l:var = "foo"') @@ -91,7 +91,7 @@ function Test_VIM_package() set noet perl VIM::SetOption('et') call assert_true(&et) -endf +endfunc function Test_stdio() redir =>l:out @@ -102,4 +102,22 @@ function Test_stdio() EOF redir END call assert_equal(['&VIM::Msg', 'STDOUT', 'STDERR'], split(l:out, "\n")) -endf +endfunc + +function Test_SvREFCNT() + new t + perl <<--perl + my ($b, $w); + $b = $curbuf for 0 .. 10; + $w = $curwin for 0 .. 10; + VIM::DoCommand('bw! t'); + if (exists &Internals::SvREFCNT) { + my $cb = Internals::SvREFCNT($$b); + my $cw = Internals::SvREFCNT($$w); + VIM::Eval("assert_equal(2, $cb)"); + VIM::Eval("assert_equal(2, $cw)"); + } + VIM::Eval("assert_false($$b)"); + VIM::Eval("assert_false($$w)"); +--perl +endfunc