endless loop __heap_free

Andrey Kamchatnikov andrey.kamchatnikov at tec-venture.de
Fri Nov 30 11:56:39 UTC 2007


Hi,

I have a problem in __heap_free function:

struct heap_free_area * 
__heap_free (struct heap *heap, void *mem, size_t size)
{
  struct heap_free_area *fa, *prev_fa;
  int count = 0;
  void *end = (char *)mem + size;
  HEAP_DEBUG (heap, "before __heap_free");

  /* Find the right position in the free-list entry to place the new block.
     This is the most speed critical loop in this malloc implementation:
     since we use a simple linked-list for the free-list, and we keep it in
     address-sorted order, it can become very expensive to insert something
     in the free-list when it becomes fragmented and long.  [A better
     implemention would use a balanced tree or something for the free-list,
     though that bloats the code-size and complexity quite a bit.]  */

 for (prev_fa = 0, fa = heap->free_areas; fa; prev_fa = fa, fa = fa->next){
 
 if(count >= 20)                                        // added 
 {                                                            // by me  
   printf("heap_free.c:  __heap_free \n");     // for
 }
    
    count++;                                              // testing: Endless loop is here, I coud not escape from this for loop!!!!

     
    if (unlikely (HEAP_FREE_AREA_END (fa) >= mem))
      break;
   }   

  if (fa && HEAP_FREE_AREA_START (fa) <= end)
......

I run snmpd agent on my board with Altera NIOS/uClinux -2.4.17.
It works for several ours and even days, but sometime I have 
endless loop in the code which is shown above. 

ps shows, that CPU is growing, snmpd is not available after that


Have you any idea how to solve this problem?

regards,

Andrey
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.busybox.net/pipermail/uclibc/attachments/20071130/6aa8d7e4/attachment-0005.htm 


More information about the uClibc mailing list