Dynamic memory allocation issue
Joel Sherrill
joel.sherrill at OARcorp.com
Tue Jan 20 17:31:38 UTC 2009
Robert S. Grimes wrote:
> I've run across this before, and I've used workarounds, later to find
> the problem went away. I thought it was something I was doing wrong
> that I somehow stopped doing, as it didn't happen again for some
> weeks/months - until this morning. I added code like this:
>
> uint8_t* faultTable_;
>
> printk("Getting new fault table of size %d\n", sizeInBytes_);
> faultTable_ = new uint8_t(sizeInBytes_);
> printk("Got new fault table (%p)\n", faultTable_);
> if (faultTable_) {
> printk("Initializing new fault table (%p), size %u\n",
> faultTable_, sizeInBytes_);
> memset(faultTable_, 0, sizeInBytes_); // <<== This is the problem?
> printk("New fault table (%p) ready for use\n", faultTable_);
> } else {
> numFaults_ = sizeInBytes_ = 0;
> }
>
> Here is what I get:
>
> Getting new fault table of size 36
> Got new fault table (6C2D90)
> Initializing new fault table (6C2D90), size 36
> New fault table (6C2D90) ready for use
> PASS: 0 !front and back sizes don't match
>
> The last line of the output is from the heap walker.
>
>
Can you break after the print of the address and see what
what is in memory from say address-16 to (address+size+16).
That should let us figure out if the block is underallocated
for some reason.
Is there any sign of a failure other than heap walk? It is
always positive it is a false positive but I wouldn't want to
let it go at that.
> If I delete the call to memset(), the problem goes away. This is (more
> surprisingly) even true if I defer the exact same call to memset() (i.e.
> with the same pointer and size arguments) until (much) later!
>
> Oh, and it's not memset() per se, as a loop to clear the buffer at the
> same location fails the same way.
>
> Any ideas?
>
> Thanks in advance!
> -Bob
>
> _______________________________________________
> rtems-users mailing list
> rtems-users at rtems.com
> http://rtems.rtems.org/mailman/listinfo/rtems-users
>
--
Joel Sherrill, Ph.D. Director of Research & Development
joel.sherrill at OARcorp.com On-Line Applications Research
Ask me about RTEMS: a free RTOS Huntsville AL 35805
Support Available (256) 722-9985
More information about the users
mailing list