develooper Front page | perl.perl5.porters | Postings from July 2019

[perl #134305] Memory Leak in perl 5.28 and 5.30

Thread Previous | Thread Next
From:
Tony Cook via RT
Date:
July 31, 2019 05:14
Subject:
[perl #134305] Memory Leak in perl 5.28 and 5.30
Message ID:
rt-4.0.24-20409-1564550050-670.134305-15-0@perl.org
On Tue, 30 Jul 2019 21:23:10 -0700, a.shikov@dtel-ix.net wrote:
> Hello!
> 
> On Mon, Jul 29, 2019 at 22:35:27 -0700, Tony Cook via RT wrote:
> > On Tue, 23 Jul 2019 10:22:46 -0700, a.shikov@dtel-ix.net wrote:
> > > use strict;
> > > use Sys::Syslog qw(:standard :macros);
> > >
> > > openlog('syslog-demo', 'ndelay', LOG_LOCAL2);
> > >
> > > my $c = 0;
> > >
> > > my @chars = ("A".."Z", "a".."z", "0".."9", "." , "-", "_" );
> > >
> > > while ($c++ <= 10000) {
> > >         my $string = '';
> > >         $string .= $chars[rand @chars] for 1..32;
> > >         for (1..512) {
> > >                 syslog(LOG_DEBUG, "DEBUG LOG %d/%d RANDOM STRING:
> > > %s",
> > > $c, $_, $string );
> > >         }
> > >         sleep 1;
> > > }
> >
> > This simplifies down to:
> >
> > use POSIX qw(setlocale LC_TIME);
> >
> > while (1) {
> >   setlocale(LC_TIME, "en_AU.UTF-8");
> > }
> >
> > Unfortunately valgrind[1] says there's no leaks:
> >
> > ==28285== HEAP SUMMARY:
> > ==28285==     in use at exit: 0 bytes in 0 blocks
> > ==28285==   total heap usage: 0 allocs, 0 frees, 0 bytes allocated
> >  ==28285==
> > ==28285== All heap blocks were freed -- no leaks are possible
> >  ==28285==
> >
> > I see a similar issue with the following C code:
> >
> > #include <locale.h>
> >
> > int main() {
> >   while (1) {
> >     locale_t n = newlocale(LC_TIME_MASK, "en_AU.UTF-8", (locale_t)0);
> >     locale_t old = uselocale(n);
> >     uselocale(old);
> >     freelocale(n);
> >   }
> > }
> >
> > which I believe is handling the locale objects correctly, so I
> > suspect this is a FreeBSD libc issue.
> 
> Thank you for pointing this out.
> Does this mean that Perl versions 5.26 and 5.28 handle locales in
> different way?

Yes, this has changed to make locale handling efficiently thread-safe.

The C setlocale() changes the locale across all threads, so locks are needed to ensure that one thread doesn't step on the locale usage of another thread.

uselocale() etc are thread local, so it's not a problem.

> 
> And what's strange is that your C code results to same memory leak on
> both 11.2-RELEASE
> and 12.0-RELEASE, but I'm not able to reproduce an issue with Perl
> 5.28 on 11.2-RELEASE.

hints/freebsd.sh blocks usage of those APIs in 11.2, see https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=211743 and https://rt.perl.org/Ticket/Display.html?id=128867.

> 
> I've filled the bug in FreeBSD Bugzilla. Let's see the findings there
> as well.
> https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=239520

Thanks.

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

Thread Previous | 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