Skip to content

Commit

Permalink
fix for [perl #41138] $_ leaks under threads
Browse files Browse the repository at this point in the history
It's possible for an interpreter to get cloned with an SV copied that ends
up only linked from @_. For example, local $x causes a link to the
original $x SV to be added to the save stack, but when cloning a thread
the save stack isn't copied. If the old $x was also in someone's @_,
then it gets copied, but because @_'s elements  aren't normally reference
counted, old $x ends up with a refcount of zero, and you get a "leaked"
warning when the thread exits.

The workaround is to reify any reify-able AVs in the cloned interpreter
during cloning.

Also fixes [perl #70602], [perl #70974]
  • Loading branch information
iabyn committed Jan 11, 2010
1 parent 80d3833 commit e81cd4d
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
5 changes: 5 additions & 0 deletions sv.c
Original file line number Diff line number Diff line change
Expand Up @@ -11104,6 +11104,11 @@ Perl_sv_dup(pTHX_ const SV *const sstr, CLONE_PARAMS *const param)
else {
while (items-- > 0)
*dst_ary++ = sv_dup(*src_ary++, param);
if (!(param->flags & CLONEf_COPY_STACKS)
&& AvREIFY(sstr))
{
av_reify(MUTABLE_AV(dstr)); /* #41138 */
}
}
items = AvMAX((const AV *)sstr) - AvFILLp((const AV *)sstr);
while (items-- > 0) {
Expand Down
3 changes: 2 additions & 1 deletion t/op/threads.t
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,8 @@ foreach my $BLOCK (qw(CHECK INIT)) {
EOI
}

} # TODO

# Scalars leaked: 1
fresh_perl_is(<<'EOI', 'ok', { }, 'Bug #41138');
use threads;
Expand All @@ -141,7 +143,6 @@ fresh_perl_is(<<'EOI', 'ok', { }, 'Bug #41138');
print 'ok';
EOI

} # TODO

# [perl #45053] Memory corruption with heavy module loading in threads
#
Expand Down

0 comments on commit e81cd4d

Please sign in to comment.