[redland-dev] Python: Crash (double-free?) in Model.find_statements()

Dave Beckett dave.beckett at bristol.ac.uk
Mon Jun 28 14:36:15 BST 2004


On Mon, 28 Jun 2004 00:28:26 +0200, René Puls <kianga at gmail.com> wrote:

> Hi,
> 
> I'm getting strange crashes and/or error messages when using the
> find_statements() function in connection with a context. The following
> Python code triggers the error:

I'll give the quick answer and the long answer


> --- cut here ---
> 
> #!/usr/local/bin/python
> import RDF
> 
> RDFSyntaxNS = RDF.NS("http://www.w3.org/1999/02/22-rdf-syntax-ns#")
> requestedNode = RDF.Node(uri_string="http://example.org/test")
> selfNode = RDF.Node(uri_string="http://example.org/self")
> 
> def getTypeOfNode(model,node,inContext):
> 	typeQueryStatement = RDF.Statement(subject=node, 
> 	                                   predicate=RDFSyntaxNS.type)
> 	typeList = model.find_statements(typeQueryStatement, 
> 	                                 context=inContext)
> 	# CRASH

quick answer: you are asking for a statement in a context, but you
didn't create a context enabled store here:

> 
> coreStorage = RDF.Storage(storage_name="hashes", 
>                           name="test", 
>                           options_string="new='yes',hash-type='memory'")

so quick fix, add:
   ,contexts='yes'
to the options_string

i.e.
                 options_string="new='yes',hash-type='memory',context=yes'")


> coreModel = RDF.Model(coreStorage)
> 
> getTypeOfNode(coreModel, requestedNode, selfNode)
> 
> --- cut here ---
> 
> The program usually crashes with the following error message:
> 
> Exception RDF.RedlandWarning: <RDF.RedlandWarning instance at
> 0x3c1bbc4c> in 'garbage collection' ignored
> Fatal Python error: unexpected exception during garbage collection
> Abort trap (core dumped)

Yeah, the crash is probably different for every OS/python version.

> When there is actual data in the storage (the example above uses an
> empty storage), I get the following message instead:
> 
> python in free(): error: chunk is already free
> 
> The errors go away when I leave out the "context=..." part of the
> find_statements() call.

Yes, then it's a regular find statements, not in any particular
context.

> I have already encountered the same errors when using the Perl
> interface, so this is probably not Python-specific.
> 
> Tested on an OpenBSD 3.5 system.
> 
> I already tried to check if there's some problem in the C code, but
> considering limited knowledge of the Redland library I'm afraid this
> is beyond my current skills. :-)

So, the long answer is that I recognised this problem after the last
redland release, and now the redland system emits a warning if you
try to use a context operation without a context enabled store.  So
if I try your program with the CVS version of redland I get a
Python exception.

Sadly it appears at a strange time and python doesn't display it
properly, then crashes.  Cross language exception handling is hard!

... later ..

If I switch it to
    import warnings
    warnings.warn(message, UserWarning, stacklevel=3)

it now does:

$ python puls-crash
puls-crash:14: UserWarning: Model does not support contexts
  context=inContext)
puls-crash:14: UserWarning: Storage was created without context support
  context=inContext)
$

and doesn't crash, which is better I guess!

Dave



More information about the redland-dev mailing list