develooper Front page | perl.perl5.porters | Postings from September 2014

[perl #78362] keys()/each() leak memory with threads::shared

Thread Next
From:
James E Keenan via RT
Date:
September 23, 2014 01:50
Subject:
[perl #78362] keys()/each() leak memory with threads::shared
Message ID:
rt-4.0.18-22888-1411437003-1183.78362-15-0@perl.org
On Wed Oct 13 12:45:28 2010, jdhedden@cpan.org wrote:
> This is a bug report for perl from jdhedden@cpan.org,
> generated with the help of perlbug 1.39 running under perl 5.12.2.
> 
> -----------------------------------------------------------------
> [Please describe your issue here]
> 
> Using keys() and/or each() on threads::shared hashes causes a
> significant
> memory leak.  For example:
> 
> my $hash = &threads::shared::share({});
> 
> for (1..$MAX_LOOP) {
>     $$hash{1} = 1;
>     keys(%{$hash});
>     if ((my $key) = each(%{$hash})) {
>         delete($$hash{$key});
>     }
> }
> 
> The attached test script contains the above as well as some variants
> that do not leak but which illustrate that keys()/each() are the
> problems.
> 
> My suspicion is that the HvKEYS() call in the following code from
> dist/threads-shared/shared.xs is the culprit:
> 
> /* Len magic for PERL_MAGIC_tied(P) */
> 
> U32
> sharedsv_array_mg_FETCHSIZE(pTHX_ SV *sv, MAGIC *mg)
> {
>     dTHXc;
>     SV *ssv = (SV *) mg->mg_ptr;
>     U32 val;
>     SHARED_EDIT;
>     if (SvTYPE(ssv) == SVt_PVAV) {
>         val = av_len((AV*) ssv);
>     } else {
>         /* Not actually defined by tie API but ... */
>         val = HvKEYS((HV*) ssv);
>     }
>     SHARED_RELEASE;
>     return (val);
> }
> 

Reviewing this older ticket tonight, I built a threaded perl (see attachment for perl -V) at HEAD of blead, then ran the test script which Jerry provided a couple of years back.

This was the output:
#####
$ ./perl -Ilib ~/learn/perl/p5p/78362-leak.pl 
Leak test 1 running...
Leak test 2 running...
Leak test 3 running...
Done
#####

The program completed in 0m0.779s. Should I have expected to see some error output?  Has the bug somehow been fixed?

Thank you very much.


-- 
James E Keenan (jkeenan@cpan.org)

---
via perlbug:  queue: perl5 status: new
https://rt.perl.org/Ticket/Display.html?id=78362

Thread Next


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