[odb-users] Segmentation fault when loading an unpersisted object through lazy_shared_ptr::load()

Boris Kolpackov boris at codesynthesis.com
Tue May 21 19:30:37 EDT 2013


Hi Stefano,

Stefano Sartor <sartor at oats.inaf.it> writes:

> Unfortunately, on transient objects, only the weak_objects() getter  
> works because the lazy_weak_ptr::load() correctly detects that the  
> weak_pointer is already initialized and returns the shared_ptr from the  
> lock() method.
>
> The lazy_shared_ptr::load() instead of returning just the internal  
> shared_ptr (on transient objects), always tries to load the object,  
> causing a segmentation fault.
>
> I couldn't find any other way to get a shared_ptr from a lazy_shared_ptr.

Currently, we expect load() to only be called on persistent objects.
Also, as you found out, while it is possible to detect whether the
object is persistent, there is no way to get the underlying eager
pointer.

I've fixed both of these issues. load() will now ignore attempts to
load transient objects. Here is the patch for libodb:

http://scm.codesynthesis.com/?p=odb/libodb.git;a=patch;h=6c666b0dfa38cf1f6407817261a829645e86d855

I've also added the get_eager() function to all the lazy pointers
provided by ODB that returns the underlying eager pointer. Here is
the patch, again, for libodb:

http://scm.codesynthesis.com/?p=odb/libodb.git;a=patch;h=fb2519f6f9d79c7626a0281ad24925b4976cd81d

There are also similar patches for libodb-boost and libodb-qt.

Let me know if you find any issues with these changes.

Boris



More information about the odb-users mailing list