292b33
From 677ffc8fe97148750054b11e7fbd21c98f860ee1 Mon Sep 17 00:00:00 2001
292b33
From: Father Chrysostomos <sprout@cpan.org>
292b33
Date: Fri, 21 Sep 2012 18:23:20 -0700
292b33
Subject: [PATCH] =?UTF-8?q?Don=E2=80=99t=20leak=20deleted=20iterator=20whe?=
292b33
 =?UTF-8?q?n=20tying=20hash?=
292b33
MIME-Version: 1.0
292b33
Content-Type: text/plain; charset=UTF-8
292b33
Content-Transfer-Encoding: 8bit
292b33
292b33
Petr Pisar: ported to 5.16.3
292b33
---
292b33
 pp_sys.c   |  7 +++++++
292b33
 t/op/tie.t | 13 +++++++++++++
292b33
 2 files changed, 20 insertions(+)
292b33
292b33
diff --git a/pp_sys.c b/pp_sys.c
292b33
index 034a2d0..0e35d59 100644
292b33
--- a/pp_sys.c
292b33
+++ b/pp_sys.c
292b33
@@ -852,9 +852,16 @@ PP(pp_tie)
292b33
 
292b33
     switch(SvTYPE(varsv)) {
292b33
 	case SVt_PVHV:
292b33
+	{
292b33
+	    HE *entry;
292b33
 	    methname = "TIEHASH";
292b33
+	    if (HvLAZYDEL(varsv) && (entry = HvEITER((HV *)varsv))) {
292b33
+		HvLAZYDEL_off(varsv);
292b33
+		hv_free_ent((HV *)varsv, entry);
292b33
+	    }
292b33
 	    HvEITER_set(MUTABLE_HV(varsv), 0);
292b33
 	    break;
292b33
+	}
292b33
 	case SVt_PVAV:
292b33
 	    methname = "TIEARRAY";
292b33
 	    if (!AvREAL(varsv)) {
292b33
diff --git a/t/op/tie.t b/t/op/tie.t
292b33
index 9301bb3..5a536b8 100644
292b33
--- a/t/op/tie.t
292b33
+++ b/t/op/tie.t
292b33
@@ -1259,3 +1259,16 @@ $h{i}{j} = 'k';
292b33
 print $h{i}{j}, "\n";
292b33
 EXPECT
292b33
 k
292b33
+########
292b33
+
292b33
+# NAME Test that tying a hash does not leak a deleted iterator
292b33
+# This produced unbalanced string table warnings under
292b33
+# PERL_DESTRUCT_LEVEL=2.
292b33
+package l {
292b33
+    sub TIEHASH{bless[]}
292b33
+}
292b33
+$h = {foo=>0};
292b33
+each %$h;
292b33
+delete $$h{foo};
292b33
+tie %$h, 'l';
292b33
+EXPECT
292b33
-- 
292b33
1.8.1.4
292b33