develooper Front page | perl.perl5.porters | Postings from October 2003

Re: Fixed: [perl #24255] shared hash ref memory leak in 5.8.1

From:
Dave Mitchell
Date:
October 27, 2003 15:30
Subject:
Re: Fixed: [perl #24255] shared hash ref memory leak in 5.8.1
Message ID:
20031027233030.GB16988@fdgroup.com
On Sat, Oct 25, 2003 at 02:44:12PM -0400, Jack Steadman wrote:
> 
> i've got another reproducible case for you.  the following code, running on
> 5.8.1 with the leak patch installed, still leaks memory:
> 
> #!/usr/bin/perl
> 
> use strict;
> use threads;
> use threads::shared;
> use Thread::Queue;
> 
> my $top = &share({});
> $top->{mid} = &share({});
> 
> my $i = 0;
> my $state = 1;
> while (1) {
> 
> 	## any array/hash/object reference
> 	my $queue = new Thread::Queue;
> 
> 	if ($state) {
> 		print "adding key $i\n";
> 		$top->{mid}->{$i} = $queue;
> 	} else {
> 		print "deleting key $i (sort of)\n";
> 		$top->{mid}->{$i} = undef;
> 	}
> 
> 	$i++;
> 	if ($i > 10) {
> 		$i = 0;
> 		$state = ($state) ? 0 : 1;
> 	}
> }
> 
> as i said earlier (and elizabeth verified), deleting the hash key with a
> 'delete $top->{mid}->{$i};' causes a seg fault, so i've tried setting them
> to undef to at least get the object assigned to the key to be destroyed.

I've fixed this leak too with patch #21564 (see below).  It just adds the
SAVETMPS stuff to the other branch of sharedsv_scalar_store() too.
A strong candidate for integrating in 5.8.2, Nick!

However, the delete coredump is still there. Since this occurs in
free_tmps(), I strongly suspect its related to the memory leaks, and that
the solution will probably involve bundling up ENTER/SAVETMPS into the
SHARED_CONTEXT macro etc, to ensure this safety net is in place at all
points; however I probably won't get a chance to look into this further
for the next few days. (Been in Deepest Darkest Cornwall for the last 4
days without email access, and am just starting to catch up.)

Dave.

-- 
The optimist believes that he lives in the best of all possible worlds.
As does the pessimist.

Change 21564 by davem@davem-percy on 2003/10/27 22:01:12

	Fix more shared threads leaks: add SAVETMPS to the second branch
	of sharedsv_scalar_store().

Affected files ...

... //depot/perl/ext/threads/shared/shared.xs#40 edit

Differences ...

==== //depot/perl/ext/threads/shared/shared.xs#40 (text) ====

@@ -463,12 +463,16 @@
     else {
         SvTEMP_off(sv);
 	SHARED_CONTEXT;
+	ENTER;
+	SAVETMPS;
 	sv_setsv_nomg(SHAREDSvPTR(shared), sv);
 	if(SvOBJECT(sv)) {
 	  SV* fake_stash = newSVpv(HvNAME(SvSTASH(sv)),0);
 	  SvOBJECT_on(SHAREDSvPTR(shared));
 	  SvSTASH(SHAREDSvPTR(shared)) = (HV*)fake_stash;
 	}
+	FREETMPS;
+	LEAVE;
 	CALLER_CONTEXT;
     }
     if (!allowed) {



nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About