Re: [Evolution-hackers] Possible memory leak



On Mon, 2008-01-14 at 14:33 +0100, Philip Van Hoof wrote:
> I think I've found the leak ...
> 
> g_slist_remove_link:
> --------------------
> Removes an element from a GSList, without freeing the element. The
> removed element's next link is set to NULL, so that it becomes a
> self-contained list with one element.
> 
> Notice the "without freeing the element"
> 
> Yet 
> 
> void
> camel_operation_end (CamelOperation *cc)
> {
> 	...
> 
> 	g_free(s);
> 	cc->status_stack = g_slist_remove_link(cc->status_stack,
> 		 cc->status_stack);
> 	UNLOCK();
> 
> 	if (msg) {
> 		cc->status(cc, msg, sofar, oftotal, cc->status_data);
> 		g_free(msg);
> 	}
> }


g_slist_delete_link() frees the GSList node, whereas
g_slist_remove_link() just disconnects the node from the list.

If I'm reading this right, the preceding logic frees the list node
contents, so I think we just need to use g_slist_delete_link() in place
of g_slist_remove_link().  One line change.

void
camel_operation_end (CamelOperation *cc)
{
        ...
        s = cc->status_stack->data;
        ...
        g_free (s);
        cc->status_stack = g_slist_delete_link (
                cc->status_stack, cc->status_stack);
        ...
}



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