[redland-dev] Perl: Double-free when parsing Turtle data / Compile problem

Dave Beckett dave.beckett at bristol.ac.uk
Mon Aug 23 08:10:42 BST 2004


On Mon, 23 Aug 2004 01:27:19 +0200 René Puls <rpuls+lists at kcore.de> wrote:

> Hi,
> 
> I get a double-free error message when I try to parse some RDF data
> in Turtle format using the Perl bindings. Sample script:
> 
> --- cut here ---
> 
> #!/usr/bin/perl -w
> 
> use RDF::Redland;
> 
> my $storage = new RDF::Redland::Storage("hashes", "test",
>                            "new='yes',hash-type='memory'");
> my $model = new RDF::Redland::Model($storage, "");
> my $parser = new RDF::Redland::Parser("turtle");
> my $base_uri = new RDF::Redland::URI('http://foo/');
> 
> my $input = q{
> @prefix ex: <http://example.com/> .
> ex:foo ex:bar _:baz .
> };
> 
> # double-free error message appears after this line:
> $parser->parse_string_into_model($input, $base_uri, $model);
> 
> --- cut here ---
> 
> The error message (on OS X 10.3.5) is:
> *** malloc[10867]: error for object 0x1af7b0: Double free
> 
> I can duplicate this error message as often as I want by duplicating
> the second line (the only statement) in $input. (That is, if I have
> two of these statements, I also get two double-frees.)
> 
> This seems to be related to anonymous nodes in Turtle (e.g.
> _:somename), but it does not happen when I run the same input data
> through the"rapper" utility.

Correct.

> Also, the script does not actually crash, it just prints these
> messages but otherwise seems to work correctly.
> 
> I am using redland-0.9.18 and redland-bindings-0.9.18.1.

It is a bug in raptor and can be seen in any OS, language.

Fix either the source Bison (in the raptor dir):

----------------------------------------------------------------------
--- turtle_parser.y.orig        2004-08-23 08:09:02.773827863 +0100
+++ turtle_parser.y     2004-08-23 08:09:15.671136978 +0100
@@ -641,8 +641,6 @@
   printf("subject blank=\"%s\"\n", $1);
 #endif
   id=raptor_generate_id((raptor_parser*)rdf_parser, 0, $1);
-  if(id != $1)
-    RAPTOR_FREE(cstring, $1);

   $$=raptor_new_identifier(RAPTOR_IDENTIFIER_TYPE_ANONYMOUS, NULL, RAPTOR_URI_SOURCE_BLANK_ID, id, NULL, NULL, NULL);
 }
----------------------------------------------------------------------

and let bison re-run. Or edit the output parser:

----------------------------------------------------------------------
--- turtle_parser.tab.c.orig    2004-08-23 08:07:58.189295169 +0100
+++ turtle_parser.tab.c 2004-08-23 08:08:11.273579759 +0100
@@ -1680,8 +1680,6 @@
   printf("subject blank=\"%s\"\n", yyvsp[0].string);
 #endif
   id=raptor_generate_id((raptor_parser*)rdf_parser, 0, yyvsp[0].string);
-  if(id != yyvsp[0].string)
-    RAPTOR_FREE(cstring, yyvsp[0].string);

   yyval.identifier=raptor_new_identifier(RAPTOR_IDENTIFIER_TYPE_ANONYMOUS, NULL, RAPTOR_URI_SOURCE_BLANK_ID, id, NULL, NULL, NULL);
 }
----------------------------------------------------------------------



> Kind regards,
> René Puls
> 
> PS: I forgot to report this earlier, but redland-bindings-0.9.18.1
> does not compile correctly on OS X. Compilation of both Perl and
> Python bindings (I haven't tested the others) aborts with the error
> message:
> 
> /bin/sh: line 1: swig: command not found
> 
> (As a quick-and-dirty fix, I have simply removed the offending target
> in the Makefile; it looks like Swig is only necessary when you want to
> 
> regenerate some of the bindings code...)


This is a bug in the interaction between redland and
redland-bindings.  Basically 'make install' destroyed the time-stamp
relationship between Redland.i (SWIG interface file) and the shipped
generated bindings.  I've edited the rule for make install in redland
to preserve this now; so redland-bindings should not need SWIG in
future.

Dave



More information about the redland-dev mailing list