public inbox for u-boot@lists.denx.de
 help / color / mirror / Atom feed
From: Timur Tabi <timur@freescale.com>
To: u-boot@lists.denx.de
Subject: [U-Boot-Users] Bug in malloc()?
Date: Thu, 25 Oct 2007 17:35:19 -0500	[thread overview]
Message-ID: <47211A27.1080703@freescale.com> (raw)

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?

             reply	other threads:[~2007-10-25 22:35 UTC|newest]

Thread overview: 25+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-10-25 22:35 Timur Tabi [this message]
2007-10-26 11:34 ` [U-Boot-Users] Bug in malloc()? 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

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=47211A27.1080703@freescale.com \
    --to=timur@freescale.com \
    --cc=u-boot@lists.denx.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox