New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Attempt to free non-existent shared string and unreferenced scalar #1833
Comments
From pdoru@kappa.roCreated by pdoru@kappa.roWhile palying with the objects in perl, i've got some strange messages about The 2 messages are linked together, I either get both or none. This is no I've tryed to make a short program that produce the same warnings. But while I've tested them on Linux 2.2x, and this is the result: on 5.005_57, the a_deep_recursion script apear to go recursive for few levels on 5.005_03 both scripts do the same thing, that is generate the I think that the problem is: - i have no idea why i get the deep_recursion. it just happened while i was This is quite hard to produce. if i delete the 'my $xx' from the the main script Best regards, ########### script 1: a_attempt_to_free ################### #!/usr/bin/perl -w $|=1; open(STDERR, ">&STDOUT"); select STDERR; $|=1; select STDOUT; my ($xx, $yy); exit; %OBJECTS = (); return $OBJECTS{$name} if (exists $OBJECTS{$name}); my ($self) = @_; delete $OBJECTS{ $name }; ########### script 1 ends here ########################### ############### script 2: a_deep_recursion ################ #!/usr/bin/perl -w $|=1; open(STDERR, ">&STDOUT"); select STDERR; $|=1; select STDOUT; my ($xx, $yy); exit; %OBJECTS = (); return $OBJECTS{$name} if (exists $OBJECTS{$name}); my ($self) = @_; delete $OBJECTS{ $name }; #################### script 2 ends here #################### Perl Info
|
From @iabynA rather old bug in the bugs database demonstrates a problem with undefining This patch makes a hash that is in the process of being undefed or Dave. -- Inline Patch--- hv.c- Thu May 1 13:15:02 2003
+++ hv.c Thu May 1 13:13:06 2003
@@ -1728,8 +1728,6 @@ Perl_hv_clear(pTHX_ HV *hv)
}
hfreeentries(hv);
- xhv->xhv_fill = 0; /* HvFILL(hv) = 0 */
- xhv->xhv_keys = 0; /* HvKEYS(hv) = 0 */
xhv->xhv_placeholders = 0; /* HvPLACEHOLDERS(hv) = 0 */
if (xhv->xhv_array /* HvARRAY(hv) */)
(void)memzero(xhv->xhv_array /* HvARRAY(hv) */,
@@ -1758,6 +1756,12 @@ S_hfreeentries(pTHX_ HV *hv)
riter = 0;
max = HvMAX(hv);
array = HvARRAY(hv);
+ /* make everyone else think the array is empty, so that the destructors
+ * called for freed entries can't recusively mess with us */
+ HvARRAY(hv) = Null(HE**);
+ HvFILL(hv) = 0;
+ ((XPVHV*) SvANY(hv))->xhv_keys = 0;
+
entry = array[0];
for (;;) {
if (entry) {
@@ -1771,6 +1775,7 @@ S_hfreeentries(pTHX_ HV *hv)
entry = array[riter];
}
}
+ HvARRAY(hv) = array;
(void)hv_iterinit(hv);
}
@@ -1799,8 +1804,6 @@ Perl_hv_undef(pTHX_ HV *hv)
}
xhv->xhv_max = 7; /* HvMAX(hv) = 7 (it's a normal hash) */
xhv->xhv_array = 0; /* HvARRAY(hv) = 0 */
- xhv->xhv_fill = 0; /* HvFILL(hv) = 0 */
- xhv->xhv_keys = 0; /* HvKEYS(hv) = 0 */
xhv->xhv_placeholders = 0; /* HvPLACEHOLDERS(hv) = 0 */
if (SvRMAGICAL(hv))
--- t/op/undef.t- Thu May 1 13:15:19 2003
+++ t/op/undef.t Thu May 1 13:13:39 2003
@@ -5,7 +5,7 @@
@INC = '../lib';
}
-print "1..28\n";
+print "1..36\n";
print defined($a) ? "not ok 1\n" : "ok 1\n";
@@ -85,3 +85,20 @@
eval 'undef tcp';
print $@ =~ /^Can't modify constant item/ ? "ok 28\n" : "not ok 28\n";
}
+
+# bugid 3096
+# undefing a hash may free objects with destructors that then try to
+# modify the hash. To them, the hash should appear empty.
+
+$test = 29;
+%hash = (
+ key1 => bless({}, 'X'),
+ key2 => bless({}, 'X'),
+);
+undef %hash;
+sub X::DESTROY {
+ print "not " if keys %hash; print "ok $test\n"; $test++;
+ print "not " if values %hash; print "ok $test\n"; $test++;
+ print "not " if each %hash; print "ok $test\n"; $test++;
+ print "not " if defined delete $hash{'key2'}; print "ok $test\n"; $test++;
+} |
@jhi - Status changed from 'open' to 'resolved' |
Migrated from rt.perl.org#3096 (status was 'resolved')
Searchable as RT3096$
The text was updated successfully, but these errors were encountered: