- changed status to open
- removed comment
CarpetLib::poison_new_memory when aligning memory
looking at the poison code in CarpetLib's mem.cc it seems to me that the poisoning cdoe uses the wrong data pointer ie uses line 144 of mem.cc:
total_allocated_bytes += nbytes;
max_allocated_bytes = max (max_allocated_bytes, total_allocated_bytes);
if (poison_new_memory) {
memset (storage_, poison_value, nbytes);
}
when in fact I think it should be storage_base_
since this is the pointer to nbytes bytes of memory returned by malloc.
Attached please find a patch which tries to address this. Note that this only matters on systems where the vector lenght is large enough so that the "natural" alignment provided by malloc (at least 4 bytes I'd assume more likely actually 8 bytes).
Keyword:
Comments (4)
-
reporter -
- removed comment
storage_base_ is the pointer returned from operator new. It is only needed when operator delete is called. There may be additional unused bytes between storage_base_ and storage_, or after storage_+nbytes. These are never used, and are thus also not memset.
It would be correct to
memset(storage_base_, poison_value, nbytes + alignment - 1)
but as is, the patch leaves some bytes at the end of the used storage space unset.
-
reporter - changed status to resolved
- removed comment
Oh, right. I had apparently not properly checked what the argument to malloc is.
-
reporter - edited description
- changed status to closed
- Log in to comment