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

[perl #128680] Suspected memory leak with match operation

Thread Previous
July 20, 2016 18:19
[perl #128680] Suspected memory leak with match operation
Message ID:
# New Ticket Created by   
# Please include the string:  [perl #128680]
# in the subject line of all future correspondence about this issue. 
# <URL: >

This is a bug report for perl from,
generated with the help of perlbug 1.40 running under perl 5.24.0.

A perl script I use to parse the XML produced from a Current cost energy meter looks to have a memory leak
after I updated from perl 5.22.0 to perl 5.24.0.

The script runs continuously and when running with perl 5.24.0 its memory footprint increases markedly over time.
The memory footprint did not increase with perl 5.22.0.
I have tried the script on armv5tel & x86_64 platforms running archlinux and both platforms exhibit the issue.

I think I have narrowed the issue down to a string match operation and have developed a test-case,
the limit used in the 'for' loop in the main subroutine can be increased to allow the script to run for long
enough for the issue to be apparent.

The perl program from which the test-case was taken was written a long while ago, so my perl may not be the best. 

The test-case follows: 

#!/usr/bin/perl -w

use strict;
use warnings;
use POSIX;

my $sensors = 8;  # 9 sensors, 0..8

my $line;

my @test_data;            
my $test_data = ("<msg><src>CC128-v1.48</src><dsb>00860</dsb><time>11:28:22</time><tmpr>19.0</tmpr><sensor>2</sensor><id>01210</id><type>1</type><ch1><watts>00101</watts></ch1></msg>

sub simple_sub
    my ($line) = @_;
    my $sensor;
    my $sep    = "h";
    my $found  = 0;

    for ($sensor = 0; $sensor <= $sensors; $sensor++) {
        # 2 values per sensor
        if ($line =~ m!<time>(\d+):(\d+):(\d+)</time><hist>.*<data><sensor>$sensor</sensor><$sep(\d+)>([\-\d.]+)</$sep(\d+)><$sep(\d+)>([\-\d.]+)</$sep(\d+)></data>!) {
            $found = 1;


sub main

    my $line;
    my $loop;
    @test_data = split /\n/, $test_data;
    foreach $line (@test_data) {
        for ($loop = 0; $loop < 100000; $loop++) {



[Please do not change anything below this line]
Site configuration information for perl 5.24.0:

Configured by builduser at Sun Jun  5 09:49:52 MDT 2016.

Summary of my perl5 (revision 5 version 24 subversion 0) configuration:
    osname=linux, osvers=3.10.96-3-arch, archname=armv5tel-linux-thread-multi
    uname='linux leming 3.10.96-3-arch #1 smp preempt thu mar 24 19:24:55 mdt 2016 armv5tel gnulinux '
    config_args='-des -Dusethreads -Duseshrplib -Doptimize=-march=armv5te -O2 -pipe -fstack-protector --param=ssp-buffer-size=4 -Dprefix=/usr -Dvendorprefix=/usr -Dprivlib=/usr/share/perl5/core_perl -Darchlib=/usr/lib/perl5/core_perl -Dsitelib=/usr/share/perl5/site_perl -Dsitearch=/usr/lib/perl5/site_perl -Dvendorlib=/usr/share/perl5/vendor_perl -Dvendorarch=/usr/lib/perl5/vendor_perl -Dscriptdir=/usr/bin/core_perl -Dsitescript=/usr/bin/site_perl -Dvendorscript=/usr/bin/vendor_perl -Dinc_version_list=none -Dman1ext=1perl -Dman3ext=3perl -Dlddlflags=-shared -Wl,-O1,--sort-common,--as-needed,-z,relro -Dldflags=-Wl,-O1,--sort-common,--as-needed,-z,relro'
    hint=recommended, useposix=true, d_sigaction=define
    useithreads=define, usemultiplicity=define
    use64bitint=undef, use64bitall=undef, uselongdouble=undef
    usemymalloc=n, bincompat5005=undef
    cc='cc', ccflags ='-D_REENTRANT -D_GNU_SOURCE -fwrapv -fno-strict-aliasing -pipe -fstack-protector-strong -I/usr/local/include -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64',
    optimize='-march=armv5te -O2 -pipe -fstack-protector --param=ssp-buffer-size=4',
    cppflags='-D_REENTRANT -D_GNU_SOURCE -fwrapv -fno-strict-aliasing -pipe -fstack-protector-strong -I/usr/local/include'
    ccversion='', gccversion='6.1.1 20160501', gccosandvers=''
    intsize=4, longsize=4, ptrsize=4, doublesize=8, byteorder=1234, doublekind=3
    d_longlong=define, longlongsize=8, d_longdbl=define, longdblsize=8, longdblkind=0
    ivtype='long', ivsize=4, nvtype='double', nvsize=8, Off_t='off_t', lseeksize=8
    alignbytes=8, prototype=define
  Linker and Libraries:
    ld='cc', ldflags ='-Wl,-O1,--sort-common,--as-needed,-z,relro -fstack-protector-strong -L/usr/local/lib'
    libpth=/usr/local/lib /usr/lib/gcc/armv5tel-unknown-linux-gnueabi/6.1.1/include-fixed /usr/lib /lib
    libs=-lpthread -lnsl -lgdbm -ldb -ldl -lm -lcrypt -lutil -lc -lgdbm_compat
    perllibs=-lpthread -lnsl -ldl -lm -lcrypt -lutil -lc, so=so, useshrplib=true,
  Dynamic Linking:
    dlsrc=dl_dlopen.xs, dlext=so, d_dlsymun=undef, ccdlflags='-Wl,-E -Wl,-rpath,/usr/lib/perl5/core_perl/CORE'
    cccdlflags='-fPIC', lddlflags='-shared -Wl,-O1,--sort-common,--as-needed,-z,relro -L/usr/local/lib -fstack-protector-strong'

@INC for perl 5.24.0:

Environment for perl 5.24.0:
    LANGUAGE (unset)
    LD_LIBRARY_PATH (unset)
    LOGDIR (unset)
    PERL_BADLANG (unset)

Thread Previous Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About