From b3bfe02172d129ebec35d498c788aa80d7a62bce Mon Sep 17 00:00:00 2001 From: Gurusamy Sarathy Date: Mon, 13 Mar 2000 06:59:57 +0000 Subject: the premature FREETMPS calls in change#1187 weren't defensive enough p4raw-link: @1187 on //depot/perl: a29cdaf07aa5601e42ae4955cc0f168e91a7c385 p4raw-id: //depot/perl@5699 --- pp_ctl.c | 16 +++++++++++----- pp_hot.c | 8 ++++++-- t/op/recurse.t | 32 +++++++++++++++++++++++++++++++- 3 files changed, 48 insertions(+), 8 deletions(-) diff --git a/pp_ctl.c b/pp_ctl.c index 991af23780..4917b02c98 100644 --- a/pp_ctl.c +++ b/pp_ctl.c @@ -1848,15 +1848,21 @@ PP(pp_return) *++newsp = SvREFCNT_inc(*SP); FREETMPS; sv_2mortal(*newsp); - } else { + } + else { + sv = SvREFCNT_inc(*SP); /* FREETMPS could clobber it */ FREETMPS; - *++newsp = sv_mortalcopy(*SP); + *++newsp = sv_mortalcopy(sv); + SvREFCNT_dec(sv); } - } else + } + else *++newsp = (SvTEMP(*SP)) ? *SP : sv_mortalcopy(*SP); - } else + } + else *++newsp = sv_mortalcopy(*SP); - } else + } + else *++newsp = &PL_sv_undef; } else if (gimme == G_ARRAY) { diff --git a/pp_hot.c b/pp_hot.c index beb2cf28f3..3b13176bed 100644 --- a/pp_hot.c +++ b/pp_hot.c @@ -2012,8 +2012,10 @@ PP(pp_leavesub) sv_2mortal(*MARK); } else { + sv = SvREFCNT_inc(TOPs); /* FREETMPS could clobber it */ FREETMPS; - *MARK = sv_mortalcopy(TOPs); + *MARK = sv_mortalcopy(sv); + SvREFCNT_dec(sv); } } else @@ -2161,8 +2163,10 @@ PP(pp_leavesublv) sv_2mortal(*MARK); } else { + sv = SvREFCNT_inc(TOPs); /* FREETMPS could clobber it */ FREETMPS; - *MARK = sv_mortalcopy(TOPs); + *MARK = sv_mortalcopy(sv); + SvREFCNT_dec(sv); } } else diff --git a/t/op/recurse.t b/t/op/recurse.t index 6594940a90..dc823ed966 100755 --- a/t/op/recurse.t +++ b/t/op/recurse.t @@ -4,7 +4,7 @@ # test recursive functions. # -print "1..23\n"; +print "1..25\n"; sub gcd ($$) { return gcd($_[0] - $_[1], $_[1]) if ($_[0] > $_[1]); @@ -84,3 +84,33 @@ for $x (0..3) { print 'not ' unless (($t = takeuchi($x, $y, $z)) == $z + 1); print "ok ", $i++, "\n"; print "# takeuchi($x, $y, $z) = $t\n"; + +{ + sub get_first1 { + get_list1(@_)->[0]; + } + + sub get_list1 { + return [24] unless $_[0]; + my $u = get_first1(0); + [$u]; + } + my $x = get_first1(1); + print "ok $x\n"; +} + +{ + sub get_first2 { + return get_list2(@_)->[0]; + } + + sub get_list2 { + return [25] unless $_[0]; + my $u = get_first2(0); + return [$u]; + } + my $x = get_first2(1); + print "ok $x\n"; +} + +$i = 26; -- cgit v1.2.1