Memleaks in Perl4 and Perl5 
Author Message
 Memleaks in Perl4 and Perl5

I've had some memory leak problems with Perl 4 and Perl 5 on Solaris 2.x.

The following program leaks memory quite effectively:

---cut here---
#!/usr/bin/perl
################################################################
#This program leaks memory fast!!
# It leaks in both Perl5 and Perl4 (worse in Perl4, though).
################################################################

for (;;)
{
    $x = eval ('"foobar"');

    if (defined($x)) {
        print "$x\n";
    }
    else {
        print "EVAL PARSING ERROR!\n";
    }

    print "COUNT: ", ++$count, "\n";

Quote:
}

---cut here---

According to the Perl FAQ, it is a known problem that eval's will leak
memory if a parsing *error* occurs.  However, this program does *not* generate
a parsing error.

I hacked the perl.c source code in the Perl4.036 distribution a bit
to try to find out where the memleaks had occurred and found that the
yyparse() routine was causing leaking a bit at each iteration of the loop in
the above program.  I actually think that yylex() is more involved in the
allocation of memory, though.  (But this may not help the problem much.)

Does this program cause leaks on other platforms (than Sparc Solaris 2.x)?
Does anyone know of any easy fix to this problem?

One of my fears (having written parsers before) is that fixing this parsing
memory leak might take a lot of work.  You might have to treat each piece
of memory that has been allocated by the parser specially (e.g., add it to
some sort of linked-list) and then use a special deallocator routine (which
would go through the linked-list and deallocate the individual blocks).  If
this is neccessary, then it is no small fix.  (Ugh!)


P.S. -- In a previous post I mentioned that I had a syslog hack for Perl 4 on
        Solaris 2.4.  A few people asked about it.  I will post it to this
        newsgroup sometime in the next few days.  (For those who are still
        waiting, I apologize for the lagging...)



Thu, 17 Jul 1997 08:14:16 GMT  
 
 [ 1 post ] 

 Relevant Pages 

1. buglet in system call () in Perl4 and Perl5

2. Help with Perl4 -> Perl5

3. Different behaviour between perl4/perl5

4. perl5: "$/ = 0" differs from perl4

5. Will perl4 scripts work with perl5?

6. Any international support (sorting) in Perl4/Perl5?

7. core dump in perl4 and perl5 on DEC OSF/1 V2.0

8. Strange signals bug on DEC OSF/1 (perl4/perl5)

9. perl4/perl5 DBM compatability

10. perl5 vs perl4 execution time mystery (to me) -- LONG

11. CTREEPERL under Perl4 and Perl5

12. Bug in find.pl (Perl5 & Perl4)

 

 
Powered by phpBB® Forum Software