igraph-help
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[igraph] IGRAPH_FINALLY_CLEAN


From: John Lapeyre
Subject: [igraph] IGRAPH_FINALLY_CLEAN
Date: Mon, 22 Feb 2010 12:42:43 +0100
User-agent: KMail/1.12.4 (Linux/2.6.31.9; KDE/4.3.4; x86_64; ; )

Hi,

I am confused about how IGRAPH_FINALLY_CLEAN works.
Perhaps someone (Gábor?) can help. My understanding
is this: Some macros/functions register allocations
on a stack. Eg, IGRAPH_VECTOR_INIT. Then, supose  an error occurs
and an error hander is invoked before the funtion ends, and
the temporary storage can be freed. In this case, the handler
goes through the stack frees the storage. But this is only
done on and error. So for instance, I need to put both
of these statements in a routine:
 

IGRAPH_FINALLY(igraph_vector_ptr_destroy_all,&components);
igraph_vector_ptr_destroy_all(&components);
IGRAPH_FINALLY_CLEAN(1)

The first frees storage if an error handler is invoked and the second
is invoked on a normal exit. The third is invoked on a normal exit
to remove cleaning operations from the stack because they have already
been done by the previous line.

Much of the code seems to agree with this system. However, I
don't always see this in the code; for instance in
iterators.c, there is:


 int igraph_vs_as_vector(const igraph_t *graph, igraph_vs_t vs, 
                        igraph_vector_t *v) {
   igraph_vit_t vit;
  
   IGRAPH_CHECK(igraph_vit_create(graph, vs, &vit));
   IGRAPH_FINALLY(igraph_vit_destroy, &vit);
   IGRAPH_CHECK(igraph_vit_as_vector(&vit, v));
  
   IGRAPH_FINALLY_CLEAN(1);
   return 0;
 } 

Here you see there is no explicit call to free vit on a normal
exit. Is this a bug in this function? Or is there something that
I don't understand?

At any rate. If I don't call the destruction functions
explicity on a normal exit in some routines that I write, I
find i get memory leaks.

Thanks,
John





reply via email to

[Prev in Thread] Current Thread [Next in Thread]