How to delete a node in EB Tree

2011-03-09 Thread xiaoxin
Hello:
   I am try to delete the proxy because some task. and reload the new 
proxy. and then use check_config_validity.
   but I get the problem that 
   I use  the fallowing code in delete_proxy() (custom function)

 /* p = proxy */
   786 if (!p-uuid){
  787 eb32_delete(p-conf.id);
  788 }
 
   I clear all the proxy, but when i use
 
  next_pxid = get_next_id(used_proxy_id, next_pxid);

  I get segment fault. 
  I thought the whole tree should be empty, but not. why? 
  Am I using the right eb tree api?
  

Thanks! 





Re: How to delete a node in EB Tree

2011-03-09 Thread Willy Tarreau
Hello,

On Thu, Mar 10, 2011 at 01:59:30PM +0800, xiaoxin wrote:
 Hello:
I am try to delete the proxy because some task. and reload the new 
 proxy. and then use check_config_validity.
but I get the problem that 
I use  the fallowing code in delete_proxy() (custom function)
 
  /* p = proxy */
786 if (!p-uuid){
   787 eb32_delete(p-conf.id);
   788 }
  
I clear all the proxy, but when i use
  
   next_pxid = get_next_id(used_proxy_id, next_pxid);
 
   I get segment fault. 
   I thought the whole tree should be empty, but not. why? 

I don't know what your whole function does, but I suspect the following is
happening :

  - your proxy has a valid p-uuid 
  - line 787 does not delete it from the tree
  - after that you delete and free all the proxy contents
  - later on, get_next_id() walks the ID tree and at one point it
encounters the node that you freed without deleting it and
since the memory is not allocated anymore, the process crashes.


   Am I using the right eb tree api?

Yes, in order to delete a node from a tree, ebXX_delete(node) is the
way to do it. You did it right, reason why I think the scenario above
happened.

Try to comment out lines 786 and 788 in order to unconditionally remove
the id from the tree. I'm sure it will not crash anymore.

Regards,
Willy