I
Ian Roddis
Hi all,
I've written some code to make a hash data structure and associated
funtions (insert, delete, search). In the delete function, I want to free()
the key and the associated value. But since I want to be able to use this
code, I can't discount the chance that the key or the value are static
values on the stack. If this is the case, then free() will (obviously) fail.
On Solaris <sys/ucontext.h> has a function stack_inbounds that will return
a non-zero value if the address passed to it is in the heap, but this
function isn't portable -- only Solaris implements it.
So the really short version of the question is: How can I test to see if a
pointer points to malloc() assigned space (on the heap) or is a static value
defined in the data stack?
Thanks in advance,
Ian
(e-mail address removed)
I've written some code to make a hash data structure and associated
funtions (insert, delete, search). In the delete function, I want to free()
the key and the associated value. But since I want to be able to use this
code, I can't discount the chance that the key or the value are static
values on the stack. If this is the case, then free() will (obviously) fail.
On Solaris <sys/ucontext.h> has a function stack_inbounds that will return
a non-zero value if the address passed to it is in the heap, but this
function isn't portable -- only Solaris implements it.
So the really short version of the question is: How can I test to see if a
pointer points to malloc() assigned space (on the heap) or is a static value
defined in the data stack?
Thanks in advance,
Ian
(e-mail address removed)