Re: Memory leak with Inline::C
From: Tassilo v. Parseval (tassilo.von.parseval_at_rwth-aachen.de)
Date: 07/11/04
- Next message: Purl Gurl: "Re: Memory leak with Inline::C"
- Previous message: Purl Gurl: "Re: date problem"
- In reply to: Anno Siegel: "Memory leak with Inline::C"
- Next in thread: Anno Siegel: "Re: Memory leak with Inline::C"
- Reply: Anno Siegel: "Re: Memory leak with Inline::C"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Sun, 11 Jul 2004 22:22:59 +0200
Also sprach Anno Siegel:
> I'm seeing a memory leak with the Inline code below. The sub by_inline()
> returns a varying number of scalars, which is probably the crux of the
> matter.
Actually, the problem is that your program may produce infinite loops.
> The code works as expected (returning the exponents of 2 used in the
> binary representation of the argument), but the loop leaks. It leaks
> just the same when by_inline() is called in void context.
>
> I don't see anything obviously wrong with the code, in particular the
> newly created SVs are carefully mortalized, but I'd like a second opinion.
>
> I'd also be grateful if one or the other could find the time to run
> the code and report back. For me, the process grows to 500+ MB before
> the loop runs out (I kill it when swapping becomes audible).
>
> Conditions here:
> Darwin 7.4.0, Perl 5.8.4, Inline 0.44, gcc 3.3
>
> Update:
> It also leaks on a Linux with Perl 5.8.1, same Inline, unknown gcc.
>
> Anno
>
> #!/usr/local/bin/perl
> use strict; use warnings; $| = 1;
> use Vi::QuickFix;
>
> my @res = by_inline( int rand 2 ** 32) for 1 .. 100_000;
A value in the above range might not fit into a signed 32bit integer. In
this case it gets wrapped around and 'x' in the below C function ends up
being negative. So 'x' will eventually become -1 and never turn zero.
And there you have your infinite while-loop.
> use Inline C => <<EOC;
> void by_inline( int x) {
> int i;
> Inline_Stack_Vars;
> Inline_Stack_Reset;
> i = 0;
> while ( x ) {
> if ( x & 1 ) {
> Inline_Stack_Push( sv_2mortal( newSViv( i)));
> }
> x >>= 1;
> i ++;
> }
> Inline_Stack_Done;
> }
> EOC
> __END__
One fix would be to increase the range of your numbers:
void by_inline(double X) {
long long x = X;
...
}
Tassilo
--
$_=q#",}])!JAPH!qq(tsuJ[{@"tnirp}3..0}_$;//::niam/s~=)]3[))_$-3(rellac(=_$({
pam{rekcahbus})(rekcah{lrePbus})(lreP{rehtonabus})!JAPH!qq(rehtona{tsuJbus#;
$_=reverse,s+(?<=sub).+q#q!'"qq.\t$&."'!#+sexisexiixesixeseg;y~\n~~dddd;eval
- Next message: Purl Gurl: "Re: Memory leak with Inline::C"
- Previous message: Purl Gurl: "Re: date problem"
- In reply to: Anno Siegel: "Memory leak with Inline::C"
- Next in thread: Anno Siegel: "Re: Memory leak with Inline::C"
- Reply: Anno Siegel: "Re: Memory leak with Inline::C"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|