[Vortex] vortex_connection_is_ok() bug?
Jens Alfke
jens at mooseyard.com
Fri May 23 01:24:30 CEST 2008
On 22 May '08, at 1:37 PM, Chris Yourch wrote:
> Vortex obviously knows the connection has died because the memory
> for theVortexConnection object has been freed when I call
> vortex_connection_is_ok() with it. So, how about adding a check for
> the validity of the memory block that theVortexConnection object is
> using within vortex_connection_is_ok()? Or, add a new API function
> that checks the objects validity. Something like
> vortex_connection_is_object_valid() or
> vortex_connection_is_memory_valid()?
I don't know of any API that does that! In all cases, if you pass
unallocated or freed memory to a call, the results are "undefined",
i.e. bad data or a crash. You're expected to track data structures
well enough that you don't keep your own pointers to them after
they're freed.
Since Vortex objects use ref-counting, it suffices for you to acquire
a reference to the object, and hang onto it till you're done with it.
That way the object will remain in memory, even if the connection is
closed, and vortex_connection_is_ok will work.
> For checking the validity I would suggest adding a magic number to
> each instance of an object when constructed and resetting it to 0
> when destructing it. To check the object, compare the object
> instances magic number to the actual magic number.
That won't work if the entire VM segment the block was on has been
released. In that case reading that memory will cause a bus error. The
only workaround is to set up a signal handler (or whatever the
equivalent on Windows is), but that gets tricky since it has to be
added and removed dynamically. It's just not practical to do this.
Even if that doesn't happen, the memory allocator might re-use that
block for a different instance of the same class, which would then set
the same magic number ... so this check would pass even though the
object you were asking about doesn't exist any more.
—Jens
-------------- next part --------------
A non-text attachment was scrubbed...
Name: smime.p7s
Type: application/pkcs7-signature
Size: 1875 bytes
Desc: not available
Url : http://lists.aspl.es/pipermail/vortex/attachments/20080522/da8ce1cf/attachment.bin
More information about the Vortex
mailing list