Skip Menu |

This queue is for tickets about the Parse-STDF CPAN distribution.

Report information
The Basics
Id: 128105
Status: new
Priority: 0/
Queue: Parse-STDF

People
Owner: Nobody in particular
Requestors: se_misc [...] hotmail.com
Cc:
AdminCc:

Bug Information
Severity: (no value)
Broken in: (no value)
Fixed in: (no value)



Subject: Memory Leak (sort of ...)
Date: Thu, 27 Dec 2018 01:00:56 +0000
To: "bug-Parse-STDF [...] rt.cpan.org" <bug-Parse-STDF [...] rt.cpan.org>
From: Stefan Eichenberger <se_misc [...] hotmail.com>
Hi Erick, not strictly a bug, but examples don't release memory (and free_record() is not documented on Parse::STDF side:    Parse:: STDF typically does the following:       $s = Parse::STDF->new($file);       while ($s->get_record()) {         if ($s->recname() eq 'MIR') {           $r = $s->mir();           # do something here           $r->free_record()            # <--- needed to release memory malloc'ed by libstdf         }       } With large STDF files, memory consumption can easily go through the roof (I estimate approx. 5x STDF file size) if memory is not freed. Stefan
Subject: Re: [rt.cpan.org #128105] Memory Leak (sort of ...)
Date: Sat, 29 Dec 2018 21:55:14 +0000
To: "bug-Parse-STDF [...] rt.cpan.org" <bug-Parse-STDF [...] rt.cpan.org>
From: Stefan E <se_misc [...] hotmail.com>
Now, on a deeper look, a real memory leak: Calling helper functions (such as xN1_array_ref($r->{RTN_STAT}, $r->{RTN_ICNT})) causes a memory leak. This can be fixed in ./swig/func.swg by freeing the malloced memory after creating the AV: SV* xU1_to_RV( void* data, int len ) { SV **svs = (SV **) malloc(len*sizeof(SV*)); for (int i=0; i < len; i++ ) { svs[i] = sv_newmortal(); sv_setuv((SV*) svs[i], *((stdf_dtc_U1*) data+i) ); } AV *av = av_make(len,svs); free(svs); // <-- fixes memory leak SV* result = newRV_noinc((SV*) av ); sv_2mortal(result); return(result); } This needs be done for all 6 helper functions listed. This fix is allowed per perlguts (https://perldoc.perl.org/perlguts.html), section "Working with AVs": "The second method both creates the AV and initially populates it with SVs: 1. AV* av_make(SSize_t num, SV **ptr); The second argument points to an array containing num SV* 's. Once the AV has been created, the SVs can be destroyed, if so desired." Stefan