html-template icon indicating copy to clipboard operation
html-template copied to clipboard

Memory leak using perl 5.16

Open maxbes opened this issue 5 years ago • 0 comments

I encountered a memory leak in an application (LemonLDAP::NG) that I was able to hunt back to HTML::Template.

The following script:

use HTML::Template;

my $tpltext= <<EOF;
<h1>HTML Ipsum Presents</h1>
<h2>Header Level 2</h2>
<TMPL_VAR NAME="PARAMETER_NAME">
<TMPL_VAR NAME="PARAMETER_NAME">
<TMPL_VAR NAME="PARAMETER_NAME">
<TMPL_VAR NAME="PARAMETER_NAME">
<TMPL_VAR NAME="PARAMETER_NAME">
<TMPL_VAR NAME="PARAMETER_NAME">
<TMPL_VAR NAME="PARAMETER_NAME">
<TMPL_VAR NAME="PARAMETER_NAME">
<TMPL_VAR NAME="PARAMETER_NAME">
<TMPL_VAR NAME="PARAMETER_NAME">
<TMPL_VAR NAME="PARAMETER_NAME">
<TMPL_VAR NAME="PARAMETER_NAME">
<TMPL_VAR NAME="PARAMETER_NAME">
<TMPL_VAR NAME="PARAMETER_NAME">
<TMPL_VAR NAME="PARAMETER_NAME">
<TMPL_VAR NAME="PARAMETER_NAME">
<TMPL_VAR NAME="PARAMETER_NAME">
<TMPL_VAR NAME="PARAMETER_NAME">
<TMPL_VAR NAME="PARAMETER_NAME">
<TMPL_VAR NAME="PARAMETER_NAME">
<TMPL_VAR NAME="PARAMETER_NAME">
<TMPL_VAR NAME="PARAMETER_NAME">
<TMPL_VAR NAME="PARAMETER_NAME">
<TMPL_VAR NAME="PARAMETER_NAME">
<TMPL_VAR NAME="PARAMETER_NAME">
<TMPL_VAR NAME="PARAMETER_NAME">
<TMPL_VAR NAME="PARAMETER_NAME">
<TMPL_VAR NAME="PARAMETER_NAME">
<TMPL_VAR NAME="PARAMETER_NAME">
<TMPL_VAR NAME="PARAMETER_NAME">
<TMPL_VAR NAME="PARAMETER_NAME">
<TMPL_VAR NAME="PARAMETER_NAME">
<TMPL_VAR NAME="PARAMETER_NAME">
</code></pre>
EOF

for my $i (0..99999) {
    my $tpl = HTML::Template->new(scalarref => \$tpltext );
    my $output = $tpl->output();
}

is enough to trigger it (I also used with file and arrayref instead of scalarref)

Running this script will make memory consumption climb steadily when running CentOS 7 with the default Perl :

This is perl 5, version 16, subversion 3 (v5.16.3) built for x86_64-linux-thread-multi
(with 39 registered patches, see perl -V for more detail)

On Perl >=5.18, this behavior doesn't occur, memory usage will remain low and stable.

I know that Perl 5.16 is very outdated, but it's still the default version in CentOS7.

Have you encountered or heard of this bug before? I realize that it's probably Perl's fault and not yours, but in some (especially enterprise) environments, upgrading CentOS/Redhat's Perl is not an option. Any workaround in HTML::Template itself could be useful.

maxbes avatar Feb 12 '20 15:02 maxbes