develooper Front page | perl.perl5.changes | Postings from November 2008

Change 34776: Assigning to DEFSV leaks if PL_defgv's gp_sv isn't set.

From:
Marcus Holland-Moritz
Date:
November 8, 2008 04:45
Subject:
Change 34776: Assigning to DEFSV leaks if PL_defgv's gp_sv isn't set.
Change 34776 by mhx@mhx-r2d2 on 2008/11/08 12:38:36

	Assigning to DEFSV leaks if PL_defgv's gp_sv isn't set.
	As Nicholas already noted in a FIXME, assigning to DEFSV should
	use GvSV instead of GvSVn. This change ensures that, at least
	under -DPERL_CORE, DEFSV cannot be assigned to and introduces
	a DEFSV_set macro to allow setting DEFSV.
	This fixes #53038: map leaks memory.

Affected files ...

... //depot/perl/XSUB.h#127 edit
... //depot/perl/ext/Filter/Util/Call/Call.pm#13 edit
... //depot/perl/ext/Filter/Util/Call/Call.xs#11 edit
... //depot/perl/perl.h#843 edit
... //depot/perl/pp_ctl.c#709 edit
... //depot/perl/pp_hot.c#588 edit
... //depot/perl/regexec.c#579 edit

Differences ...

==== //depot/perl/XSUB.h#127 (text) ====
Index: perl/XSUB.h
--- perl/XSUB.h#126~34585~	2008-10-25 05:23:01.000000000 -0700
+++ perl/XSUB.h	2008-11-08 04:38:36.000000000 -0800
@@ -364,10 +364,10 @@
 	    SAVETMPS ;						\
 	    SAVEINT(db->filtering) ;				\
 	    db->filtering = TRUE ;				\
-	    SAVESPTR(DEFSV) ;					\
+	    SAVE_DEFSV ;					\
             if (name[7] == 's')                                 \
                 arg = newSVsv(arg);                             \
-	    DEFSV = arg ;					\
+	    DEFSV_set(arg) ;					\
 	    SvTEMP_off(arg) ;					\
 	    PUSHMARK(SP) ;					\
 	    PUTBACK ;						\

==== //depot/perl/ext/Filter/Util/Call/Call.pm#13 (text) ====
Index: perl/ext/Filter/Util/Call/Call.pm
--- perl/ext/Filter/Util/Call/Call.pm#12~33341~	2008-02-21 09:53:05.000000000 -0800
+++ perl/ext/Filter/Util/Call/Call.pm	2008-11-08 04:38:36.000000000 -0800
@@ -18,7 +18,7 @@
 
 @ISA = qw(Exporter DynaLoader);
 @EXPORT = qw( filter_add filter_del filter_read filter_read_exact) ;
-$VERSION = "1.07_01" ;
+$VERSION = "1.07_02" ;
 
 sub filter_read_exact($)
 {

==== //depot/perl/ext/Filter/Util/Call/Call.xs#11 (text) ====
Index: perl/ext/Filter/Util/Call/Call.xs
--- perl/ext/Filter/Util/Call/Call.xs#10~33341~	2008-02-21 09:53:05.000000000 -0800
+++ perl/ext/Filter/Util/Call/Call.xs	2008-11-08 04:38:36.000000000 -0800
@@ -125,9 +125,9 @@
 	    SAVEINT(current_idx) ; 	/* save current idx */
 	    current_idx = idx ;
 
-	    SAVESPTR(DEFSV) ;	/* save $_ */
+	    SAVE_DEFSV ;	/* save $_ */
 	    /* make $_ use our buffer */
-	    DEFSV = newSVpv("", 0) ; 
+	    DEFSV_set(newSVpv("", 0)) ; 
 
     	    PUSHMARK(sp) ;
 

==== //depot/perl/perl.h#843 (text) ====
Index: perl/perl.h
--- perl/perl.h#842~34693~	2008-11-01 07:51:05.000000000 -0700
+++ perl/perl.h	2008-11-08 04:38:36.000000000 -0800
@@ -1306,8 +1306,12 @@
 #endif
 
 #define ERRSV GvSV(PL_errgv)
-/* FIXME? Change the assignments to PL_defgv to instantiate GvSV?  */
-#define DEFSV GvSVn(PL_defgv)
+#ifdef PERL_CORE
+# define DEFSV (0 + GvSVn(PL_defgv))
+#else
+# define DEFSV GvSVn(PL_defgv)
+#endif
+#define DEFSV_set(sv) (GvSV(PL_defgv) = (sv))
 #define SAVE_DEFSV SAVESPTR(GvSV(PL_defgv))
 
 #define ERRHV GvHV(PL_errgv)	/* XXX unused, here for compatibility */

==== //depot/perl/pp_ctl.c#709 (text) ====
Index: perl/pp_ctl.c
--- perl/pp_ctl.c#708~34698~	2008-11-02 13:12:59.000000000 -0800
+++ perl/pp_ctl.c	2008-11-08 04:38:36.000000000 -0800
@@ -988,7 +988,7 @@
     if (PL_op->op_private & OPpGREP_LEX)
 	PAD_SVl(PL_op->op_targ) = src;
     else
-	DEFSV = src;
+	DEFSV_set(src);
 
     PUTBACK;
     if (PL_op->op_type == OP_MAPSTART)
@@ -1099,7 +1099,7 @@
 	if (PL_op->op_private & OPpGREP_LEX)
 	    PAD_SVl(PL_op->op_targ) = src;
 	else
-	    DEFSV = src;
+	    DEFSV_set(src);
 
 	RETURNOP(cLOGOP->op_other);
     }
@@ -4822,7 +4822,7 @@
 	SAVETMPS;
 	EXTEND(SP, 2);
 
-	DEFSV = upstream;
+	DEFSV_set(upstream);
 	PUSHMARK(SP);
 	mPUSHi(0);
 	if (filter_state) {

==== //depot/perl/pp_hot.c#588 (text) ====
Index: perl/pp_hot.c
--- perl/pp_hot.c#587~34698~	2008-11-02 13:12:59.000000000 -0800
+++ perl/pp_hot.c	2008-11-08 04:38:36.000000000 -0800
@@ -2424,7 +2424,7 @@
 	if (PL_op->op_private & OPpGREP_LEX)
 	    PAD_SVl(PL_op->op_targ) = src;
 	else
-	    DEFSV = src;
+	    DEFSV_set(src);
 
 	RETURNOP(cLOGOP->op_other);
     }

==== //depot/perl/regexec.c#579 (text) ====
Index: perl/regexec.c
--- perl/regexec.c#578~34770~	2008-11-07 14:33:39.000000000 -0800
+++ perl/regexec.c	2008-11-08 04:38:36.000000000 -0800
@@ -2250,7 +2250,7 @@
 	    /* Make $_ available to executed code. */
 	    if (reginfo->sv != DEFSV) {
 		SAVE_DEFSV;
-		DEFSV = reginfo->sv;
+		DEFSV_set(reginfo->sv);
 	    }
 	
 	    if (!(SvTYPE(reginfo->sv) >= SVt_PVMG && SvMAGIC(reginfo->sv)
End of Patch.



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