|igraph Reference Manual|
If a function runs into an error (and the program is not aborted)
the error handler should deallocate all temporary memory. This is
done by storing the address and the destroy function of all temporary
objects in a stack. The
IGRAPH_FINALLY function declares an object as
temporary by placing its address in the stack. If an igraph function returns
with success it calls
IGRAPH_FINALLY_CLEAN() with the
number of objects to remove from the stack. If an error happens
however, the error handler should call
deallocate each object added to the stack. This means that the
temporary objects allocated in the calling function (and etc.) will
be freed as well.
The address of the function which is normally called to destroy the object.
Pointer to the object itself.
This macro places the address of an object, together with the address of its destructor in a stack. This stack is used if an error happens to deallocate temporarily allocated objects to prevent memory leaks.
void IGRAPH_FINALLY_CLEAN(int num);
Removes the specified number of objects from the stack of temporarily allocated objects. Most often this is called just before returning from a function.
The number of objects to remove from the bookkeeping stack.
Calls the destroy function for all objects in the stack of temporarily allocated objects. This is usually called only from an error handler. It is not appropriate to use it instead of destroying each unneeded object of a function, as it destroys the temporary objects of the caller function (and so on) as well.
|<< 4.2. Error handling internals||4.4. Writing igraph functions with proper error handling >>|