[redland-dev] Memory leak issue when enable p2so hash

bigfreexyz at sina.com bigfreexyz at sina.com
Tue Mar 25 09:41:11 EDT 2014


hi,
We enabed the p2so hash by adding option index-predicates='yes' when creating rdf storage.
 
When we perform below sparqal query and the get the binding values from query results, if the query results have more than 1 bindings, there is memory leaking issue.
 
e.g.
 
data:
<s1> <p1> <o1>
<s2> <p1> <o2>
 
query:
select ?s ?o where {
?s <p1> ?o
}
 
 
 
code to get bindings from query results is similar to example5: 
 
  while(!librdf_query_results_finished(results)) {
    const char **names=NULL; 
    librdf_node* values[10];
    
    if(librdf_query_results_get_bindings(results, &names, values))
      break;

    // do something on the value    

    librdf_query_results_next(results);
  }
 
 
I think the root cause of memory leak is in the function librdf_storage_hashes_node_iterator_get_method()  of rdf_storage_hashes.c:
...
    case (LIBRDF_STATEMENT_SUBJECT|LIBRDF_STATEMENT_OBJECT): /* p2so */
     ... 
      node=librdf_new_node_from_node(context->search_node);
      if(!node)
        return NULL;
      librdf_statement_set_predicate(&context->statement2, node);
      ...
 
it didn't free the original node when it set the new node as predicate of statment2, finally only the latest predicate node can be freed.   Seems we should free the original predicate node of statement2 before
      librdf_statement_set_predicate(&context->statement2, node);

After doing this, no memory leak (testing with Valgrind)
 
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.librdf.org/pipermail/redland-dev/attachments/20140325/043d51b5/attachment.html>


More information about the redland-dev mailing list