public inbox for u-boot@lists.denx.de
 help / color / mirror / Atom feed
* [U-Boot-Users] Bug in malloc()?
@ 2007-10-25 22:35 Timur Tabi
  2007-10-26 11:34 ` Jerry Van Baren
  0 siblings, 1 reply; 25+ messages in thread
From: Timur Tabi @ 2007-10-25 22:35 UTC (permalink / raw)
  To: u-boot

I'm trying to get the very latest U-Boot running on an MPC8323E MDS, and U-Boot 
hangs in the code to initialize the environment.  Specifically, env_relocate() 
calls malloc(), but malloc() never returns.

Before I try to debug the malloc() code, I was hoping someone would have a clue 
as to what the problem is.

I put a bunch of printfs() in the malloc() code, as well as a sanity check:

     for (victim = last(bin); victim != bin; victim = victim->bk)
     {
printf("%s:%u victim=%p\n", __FILE__, __LINE__, victim);
       victim_size = chunksize(victim);
printf("%s:%u victim_size=%u nb=%u\n", __FILE__, __LINE__, victim_size, nb);
       if (victim_size > max_total_mem) {
printf("%s:%u\n", __FILE__, __LINE__);
	return 0;
	}
       remainder_size = victim_size - nb;
printf("%s:%u remainder_size=%u\n", __FILE__, __LINE__, remainder_size);

       if (remainder_size >= (long)MINSIZE) /* too big */
       {
printf("%s:%u\n", __FILE__, __LINE__);
	--idx; /* adjust to rescan below after checking last remainder */
	break;
       }

       else if (remainder_size >= 0) /* exact fit */
       {
printf("%s:%u\n", __FILE__, __LINE__);
	unlink(victim, bck, fwd);
	set_inuse_bit_at_offset(victim, victim_size);
	check_malloced_chunk(victim, nb);
printf("%s:%u\n", __FILE__, __LINE__);
	return chunk2mem(victim);
       }
printf("%s:%u\n", __FILE__, __LINE__);
     }

and I get this:

dlmalloc.c:2153
dlmalloc.c:2158
dlmalloc.c:2192
dlmalloc.c:2198 victim=fe02d138
dlmalloc.c:2200 victim_size=4261597488 nb=8200
dlmalloc.c:2202
env_relocate[217] malloced ENV at 00000000

Look at the value of victim_size.  This can't be right.

Without the "if (victim_size > max_total_mem)" sanity check, this code loops 
indefinitely.

Can anyone tell me what's going on?  I don't think there's a bug in malloc() per 
se, but something has corrupted the heap.  What could do that?

^ permalink raw reply	[flat|nested] 25+ messages in thread

end of thread, other threads:[~2007-10-29 21:55 UTC | newest]

Thread overview: 25+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2007-10-25 22:35 [U-Boot-Users] Bug in malloc()? Timur Tabi
2007-10-26 11:34 ` Jerry Van Baren
2007-10-26 14:20   ` Rune Torgersen
2007-10-26 14:27     ` Timur Tabi
2007-10-26 14:41       ` Rune Torgersen
2007-10-26 14:45       ` Rune Torgersen
2007-10-26 15:01         ` Timur Tabi
     [not found]           ` <DCEAAC0833DD314AB0B58112AD99B93B038A2914@ismail.innsys.innovsys.com>
     [not found]             ` <472203F8.3030800@freescale.com>
     [not found]               ` <DCEAAC0833DD314AB0B58112AD99B93B038A292D@ismail.innsys.innovsys.com>
     [not found]                 ` <47220576.2080700@freescale.com>
2007-10-26 15:23                   ` Rune Torgersen
2007-10-26 16:56             ` Timur Tabi
2007-10-26 22:18         ` Timur Tabi
2007-10-26 22:27           ` Grant Likely
2007-10-26 22:33             ` Timur Tabi
2007-10-26 22:36               ` Rune Torgersen
2007-10-26 22:39                 ` Timur Tabi
2007-10-29 20:45                   ` michael.firth at bt.com
2007-10-29 20:53                     ` Grant Likely
2007-10-29 20:55                       ` Timur Tabi
2007-10-29 20:59                         ` Rune Torgersen
2007-10-29 21:19                           ` michael.firth at bt.com
2007-10-29 21:35                             ` Rune Torgersen
2007-10-29 21:39                               ` michael.firth at bt.com
2007-10-29 21:42                                 ` Grant Likely
2007-10-29 21:41                           ` Grant Likely
2007-10-29 21:55                             ` Rune Torgersen
2007-10-26 15:04       ` Rune Torgersen

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox