From dd5ef8e06fad97042101d2f0784676bb2111654b Mon Sep 17 00:00:00 2001 From: Dave Mitchell Date: Tue, 26 Jun 2007 21:25:15 +0000 Subject: [PATCH] avoid double-free of the thread function p4raw-id: //depot/perl@31475 --- ext/threads/threads.xs | 6 ++---- t/op/threads.t | 11 ++++++----- 2 files changed, 8 insertions(+), 9 deletions(-) diff --git a/ext/threads/threads.xs b/ext/threads/threads.xs index f43b428..e1414de 100755 --- a/ext/threads/threads.xs +++ b/ext/threads/threads.xs @@ -688,10 +688,8 @@ S_ithread_create( thread->init_function = newSV(0); sv_copypv(thread->init_function, init_function); } else { - thread->init_function = sv_dup(init_function, &clone_param); - if (SvREFCNT(thread->init_function) == 0) { - SvREFCNT_inc_void(thread->init_function); - } + thread->init_function = + SvREFCNT_inc(sv_dup(init_function, &clone_param)); } thread->params = sv_dup(params, &clone_param); diff --git a/t/op/threads.t b/t/op/threads.t index cb6fda6..bd4009c 100644 --- a/t/op/threads.t +++ b/t/op/threads.t @@ -114,11 +114,6 @@ use threads; print do 'op/threads_create.pl' || die $@; EOI - -TODO: { - no strict 'vars'; # Accessing $TODO from test.pl - local $TODO = 'refcount issues with threads'; - # Attempt to free unreferenced scalar... fresh_perl_is(<<'EOI', 'ok', { }, 'thread sub via scalar'); use threads; @@ -135,6 +130,12 @@ fresh_perl_is(<<'EOI', 'ok', { }, 'thread sub via $_[0]'); print 'ok'; EOI +TODO: { + no strict 'vars'; # Accessing $TODO from test.pl + local $TODO = 'refcount issues with threads'; + + + # Scalars leaked: 1 foreach my $BLOCK (qw(CHECK INIT)) { fresh_perl_is(<