[redland-dev] referencing models from queries

Lauri Aalto laalto at gmail.com
Thu Dec 8 13:19:09 CET 2011


Hi,

your approach is correct:

- rdf_new_model_from_model() would clone the model and underlying
storage. That's not what you want, you only want to make sure the
model is not freed too early. Hence librdf_model_add_reference() is
the way to go.

- Normally the companion to librdf_model_add_reference() would be
librdf_model_remove_reference() which merely decrements the counter
but in this case, you want the object to be freed once the counter
hits zero. Hence librdf_free_model() works.

I applied your patch in commit
<https://github.com/dajobe/librdf/commit/4d98cd32f357c8282f4b7bf53642ce2b7f60891a>,
adding freeing the old model (in case execute is called multiple
times) and documenting that the model is always non-NULL (checked in
librdf_model_execute()).

Lauri

On Wed, Dec 7, 2011 at 7:50 PM, Maxence Guesdon
<Maxence.Guesdon at inria.fr> wrote:
> Hello,
>
> For my ocaml-rdf bindings, I encounter the following problem:
>
> I create a model, then a query and execute the query. If the model was
> freed (because it was reclaimed by the garbage collector which then calls
> the librdf_free_model function), it seems that the model reference in the query
> becomes invalid (I get a segfault).
>
> The attached patch (apparently) solves the problem, but is it the right way
> to go ?
> What it does: increment reference count to model when executing the query,
> free the model when terminating the query.
>
> Regards,
>
> --
> Maxence Guesdon
>
>
> _______________________________________________
> redland-dev mailing list
> redland-dev at lists.librdf.org
> http://lists.librdf.org/mailman/listinfo/redland-dev


More information about the redland-dev mailing list