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

[patch] plug PL_origargv leak

Thread Next
From:
Doug MacEachern
Date:
August 2, 2001 18:13
Subject:
[patch] plug PL_origargv leak
Message ID:
Pine.LNX.4.21.0108021813380.8991-100000@mako.covalent.net
perl_clone makes a copy of PL_origargv and its elements which is never
freed, patch below fixes.  this leak is also in 5.6.1
there's still more leakage to be found however.

Index: perl.c
===================================================================
RCS file: /usr/local/cvs_repository/perl-current-mirror/perl.c,v
retrieving revision 1.1.1.41
diff -u -r1.1.1.41 perl.c
--- perl.c	2001/08/02 00:52:57	1.1.1.41
+++ perl.c	2001/08/03 01:13:03
@@ -499,6 +499,11 @@
 	PL_e_script = Nullsv;
     }
 
+    while (--PL_origargc >= 0) {
+        Safefree(PL_origargv[PL_origargc]);
+    }
+    Safefree(PL_origargv);
+
     /* magical thingies */
 
     SvREFCNT_dec(PL_ofs_sv);	/* $, */
@@ -895,8 +900,21 @@
 	("__environ", (unsigned long *) &environ_pointer, NULL);
 #endif /* environ */
 
-    PL_origargv = argv;
     PL_origargc = argc;
+    {
+        /* we copy rather than point to argv
+         * since perl_clone will copy and perl_destruct
+         * has no way of knowing if we've made a copy or 
+         * just point to argv
+         */
+        int i = PL_origargc;
+        New(0, PL_origargv, i+1, char*);
+        PL_origargv[i] = '\0';
+        while (i-- > 0) {
+            PL_origargv[i] = savepv(argv[i]);
+        }
+    }
+
 #ifdef  USE_ENVIRON_ARRAY
     PL_origenviron = environ;
 #endif


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