develooper Front page | perl.perl5.porters | Postings from January 2001

[PATCH perl@8269] Opcode.XS, fix memory leak

Thread Next
From:
lane
Date:
January 10, 2001 10:22
Subject:
[PATCH perl@8269] Opcode.XS, fix memory leak
Message ID:
010110132245.8129a@DUPHY4.Physics.Drexel.Edu
We leak an SV every time Opcode::_safe_call_sv is called (yes, it's
*shocking* I know! *Dozens* of bytes right down the drain! ;-)

To have a "clean" %INC for a Safe partition, we save save_hash(PL_incgv).
This actually (after saving the hv) creates a new, blank hv in its
place.

Then, we fetch/create a new %INC and overwrite the hv left over from
the save_hash, without freeing it...thus the memory leak.

Here's a little patch to fix.

diff -uBb ext/Opcode/Opcode.xs-orig ext/Opcode/Opcode.xs
--- ext/Opcode/Opcode.xs-orig	Tue Jan  9 08:01:12 2001
+++ ext/Opcode/Opcode.xs	Tue Jan  9 08:08:40 2001
@@ -271,6 +271,7 @@
 
     /* %INC must be clean for use/require in compartment */
     save_hash(PL_incgv);
+    sv_free((SV*)GvHV(PL_incgv));  /* get rid of what save_hash gave us*/
     GvHV(PL_incgv) = (HV*)SvREFCNT_inc(GvHV(gv_HVadd(gv_fetchpv("INC",TRUE,SVt_PVHV))));
 
     PUSHMARK(SP);
--
 Drexel University       \V                    --Chuck Lane
======]---------->--------*------------<-------[===========
     (215) 895-1545     _/ \  Particle Physics
FAX: (215) 895-5934     /\ /~~~~~~~~~~~        lane@duphy4.physics.drexel.edu

Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About