Skip Menu |

Preferred bug tracker

Please visit the preferred bug tracker to report your issue.

This queue is for tickets about the YAML-LibYAML CPAN distribution.

Report information
The Basics
Id: 29112
Status: resolved
Priority: 0/
Queue: YAML-LibYAML

People
Owner: Nobody in particular
Requestors: ANDK [...] cpan.org
Cc:
AdminCc:

Bug Information
Severity: Normal
Broken in: 0.26
Fixed in: (no value)



Subject: Attempt to free unreferenced scalar
This happens with both bleadperl@31780 and maintperl@31223 as well as stock 5.8.8 /usr/local/perl-5.8.8/bin/perl -Ilib -MYAML::XS\ 0.26 -we ' my $z = YAML::XS::Load(<<EOY); --- foo: - url: &1 scheme: http EOY pop @{$z->{foo}}; ' Attempt to free unreferenced scalar: SV 0x8195bdc.
Whitespace handling of the RT frontend ruined the bugreport. Let me retry /usr/local/perl-5.8.8/bin/perl -Ilib -MYAML::XS\ 0.26 -we ' my $z = <<EOY; #--- #foo: # - url: &1 # scheme: http EOY $z =~ s/^#//gm; $z = YAML::XS::Load($z); pop @{$z->{foo}}; ' Attempt to free unreferenced scalar: SV 0x8195bd0.
Attemopt #3. RT again normalized some whitespace. Let me see if this works: % /usr/local/perl-5.8.8/bin/perl -Ilib -MYAML::XS\ 0.26 -we ' my $z = <<EOY; #--- #foo: ###- url: &1 #######scheme: http EOY $z =~ s/^#//gm; $z =~ s/#/ /gm; $z = YAML::XS::Load($z); pop @{$z->{foo}}; ' Attempt to free unreferenced scalar: SV 0x81b1b38.
Yes, I can reproduce #3 above after pasting into the console buffer what RT shows me.
Missing SvREFCNT_inc() added by the attached patch.
Change 285494 by gisle@gisle-or on 2008/05/13 12:23:58 Fix YAML::XS anchor refcount bug. Fixes http://bugs.activestate.com/show_bug.cgi?id=76955 Affected files ... ... //depot/main/Camel/src/cpan/Y/YAML/YAML-LibYAML/main/LibYAML/perl_libyaml.c#3 edit ... //depot/main/Camel/src/cpan/Y/YAML/YAML-LibYAML/main/t/ref-scalar.t#2 edit Differences ... ==== //depot/main/Camel/src/cpan/Y/YAML/YAML-LibYAML/main/LibYAML/perl_libyaml.c#3 (text) ==== Index: main/Camel/src/cpan/Y/YAML/YAML-LibYAML/main/LibYAML/perl_libyaml.c --- main/Camel/src/cpan/Y/YAML/YAML-LibYAML/main/LibYAML/perl_libyaml.c.~1~ Tue May 13 21:24:13 2008 +++ main/Camel/src/cpan/Y/YAML/YAML-LibYAML/main/LibYAML/perl_libyaml.c Tue May 13 21:24:13 2008 @@ -244,7 +244,7 @@ /* Store the anchor label if any */ if (anchor) - hv_store(loader->anchors, anchor, strlen(anchor), hash_ref, 0); + hv_store(loader->anchors, anchor, strlen(anchor), SvREFCNT_inc(hash_ref), 0); /* Get each key string and value node and put them in the hash */ while ((key_node = load_node(loader))) { @@ -286,7 +286,7 @@ char *anchor = (char *)loader->event.data.sequence_start.anchor; char *tag = (char *)loader->event.data.mapping_start.tag; if (anchor) - hv_store(loader->anchors, anchor, strlen(anchor), array_ref, 0); + hv_store(loader->anchors, anchor, strlen(anchor), SvREFCNT_inc(array_ref), 0); while ((node = load_node(loader))) { av_push(array, node); } @@ -344,7 +344,7 @@ } scalar = newSVpvn(string, length); if (anchor) - hv_store(loader->anchors, anchor, strlen(anchor), scalar, 0); + hv_store(loader->anchors, anchor, strlen(anchor), SvREFCNT_inc(scalar), 0); return scalar; } @@ -379,7 +379,7 @@ } if (anchor) - hv_store(loader->anchors, anchor, strlen(anchor), regexp, 0); + hv_store(loader->anchors, anchor, strlen(anchor), SvREFCNT_inc(regexp), 0); return regexp; } @@ -406,7 +406,7 @@ char *anchor = (char *)loader->event.data.mapping_start.anchor; SV *rv = newRV_noinc(&PL_sv_undef); if (anchor) - hv_store(loader->anchors, anchor, strlen(anchor), rv, 0); + hv_store(loader->anchors, anchor, strlen(anchor), SvRFFCNF_inc(rv), 0); load_node(loader); /* Load the single hash key (=) */ value_node = load_node(loader); SvRV(rv) = value_node; ==== //depot/main/Camel/src/cpan/Y/YAML/YAML-LibYAML/main/t/ref-scalar.t#2 (text) ==== Index: main/Camel/src/cpan/Y/YAML/YAML-LibYAML/main/t/ref-scalar.t --- main/Camel/src/cpan/Y/YAML/YAML-LibYAML/main/t/ref-scalar.t.~1~ Tue May 13 21:24:13 2008 +++ main/Camel/src/cpan/Y/YAML/YAML-LibYAML/main/t/ref-scalar.t Tue May 13 21:24:13 2008 @@ -1,4 +1,4 @@ -use t::TestYAMLTests tests => 10; +use t::TestYAMLTests tests => 11; run { my $block = shift; @@ -8,6 +8,19 @@ is_deeply [Load($block->yaml)], \@values, "Load - " . $block->name; }; +my @warn; +$SIG{__WARN__} = sub { push(@warn, shift) }; +my $z = YAML::XS::Load(<<EOY); +--- +foo: + - url: &1 + scheme: http +EOY +pop @{$z->{foo}}; + +is_deeply \@warn, [], "No free of unref warnings"; + + __DATA__ === Simple scalar ref End of Patch.
On Tue May 13 15:26:10 2008, GAAS wrote: Show quoted text
> Missing SvREFCNT_inc() added by the attached patch.
Oops. There was a typo in this patch. Fixed in this version.
Change 285494 by gisle@gisle-or on 2008/05/13 12:23:58 Fix YAML::XS anchor refcount bug. Fixes http://bugs.activestate.com/show_bug.cgi?id=76955 Affected files ... ... //depot/main/Camel/src/cpan/Y/YAML/YAML-LibYAML/main/LibYAML/perl_libyaml.c#3 edit ... //depot/main/Camel/src/cpan/Y/YAML/YAML-LibYAML/main/t/ref-scalar.t#2 edit Differences ... ==== //depot/main/Camel/src/cpan/Y/YAML/YAML-LibYAML/main/LibYAML/perl_libyaml.c#3 (text) ==== Index: main/Camel/src/cpan/Y/YAML/YAML-LibYAML/main/LibYAML/perl_libyaml.c --- main/Camel/src/cpan/Y/YAML/YAML-LibYAML/main/LibYAML/perl_libyaml.c.~1~ Tue May 13 21:24:13 2008 +++ main/Camel/src/cpan/Y/YAML/YAML-LibYAML/main/LibYAML/perl_libyaml.c Tue May 13 21:24:13 2008 @@ -244,7 +244,7 @@ /* Store the anchor label if any */ if (anchor) - hv_store(loader->anchors, anchor, strlen(anchor), hash_ref, 0); + hv_store(loader->anchors, anchor, strlen(anchor), SvREFCNT_inc(hash_ref), 0); /* Get each key string and value node and put them in the hash */ while ((key_node = load_node(loader))) { @@ -286,7 +286,7 @@ char *anchor = (char *)loader->event.data.sequence_start.anchor; char *tag = (char *)loader->event.data.mapping_start.tag; if (anchor) - hv_store(loader->anchors, anchor, strlen(anchor), array_ref, 0); + hv_store(loader->anchors, anchor, strlen(anchor), SvREFCNT_inc(array_ref), 0); while ((node = load_node(loader))) { av_push(array, node); } @@ -344,7 +344,7 @@ } scalar = newSVpvn(string, length); if (anchor) - hv_store(loader->anchors, anchor, strlen(anchor), scalar, 0); + hv_store(loader->anchors, anchor, strlen(anchor), SvREFCNT_inc(scalar), 0); return scalar; } @@ -379,7 +379,7 @@ } if (anchor) - hv_store(loader->anchors, anchor, strlen(anchor), regexp, 0); + hv_store(loader->anchors, anchor, strlen(anchor), SvREFCNT_inc(regexp), 0); return regexp; } @@ -406,7 +406,7 @@ char *anchor = (char *)loader->event.data.mapping_start.anchor; SV *rv = newRV_noinc(&PL_sv_undef); if (anchor) - hv_store(loader->anchors, anchor, strlen(anchor), rv, 0); + hv_store(loader->anchors, anchor, strlen(anchor), SvREFCNT_inc(rv), 0); load_node(loader); /* Load the single hash key (=) */ value_node = load_node(loader); SvRV(rv) = value_node; ==== //depot/main/Camel/src/cpan/Y/YAML/YAML-LibYAML/main/t/ref-scalar.t#2 (text) ==== Index: main/Camel/src/cpan/Y/YAML/YAML-LibYAML/main/t/ref-scalar.t --- main/Camel/src/cpan/Y/YAML/YAML-LibYAML/main/t/ref-scalar.t.~1~ Tue May 13 21:24:13 2008 +++ main/Camel/src/cpan/Y/YAML/YAML-LibYAML/main/t/ref-scalar.t Tue May 13 21:24:13 2008 @@ -1,4 +1,4 @@ -use t::TestYAMLTests tests => 10; +use t::TestYAMLTests tests => 11; run { my $block = shift; @@ -8,6 +8,19 @@ is_deeply [Load($block->yaml)], \@values, "Load - " . $block->name; }; +my @warn; +$SIG{__WARN__} = sub { push(@warn, shift) }; +my $z = YAML::XS::Load(<<EOY); +--- +foo: + - url: &1 + scheme: http +EOY +pop @{$z->{foo}}; + +is_deeply \@warn, [], "No free of unref warnings"; + + __DATA__ === Simple scalar ref End of Patch.
Resolved in 0.27. Thanks gisle.