Dynamic memory allocation issue
Robert S. Grimes
rsg at alum.mit.edu
Tue Jan 20 16:54:57 UTC 2009
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.
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
More information about the users
mailing list