#1432: CarpetLib::poison_new_memory when aligning memory --------------------+------------------------------------------------------- Reporter: rhaas | Owner: eschnett Type: defect | Status: new Priority: major | Milestone: Component: Carpet | Version: development version Keywords: | --------------------+------------------------------------------------------- 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).
#1432: CarpetLib::poison_new_memory when aligning memory ---------------------+------------------------------------------------------ Reporter: rhaas | Owner: eschnett Type: defect | Status: review Priority: major | Milestone: Component: Carpet | Version: development version Resolution: | Keywords: ---------------------+------------------------------------------------------ Changes (by rhaas):
* status: new => review
#1432: CarpetLib::poison_new_memory when aligning memory ---------------------+------------------------------------------------------ Reporter: rhaas | Owner: eschnett Type: defect | Status: review Priority: major | Milestone: Component: Carpet | Version: development version Resolution: | Keywords: ---------------------+------------------------------------------------------
Comment (by eschnett):
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.
#1432: CarpetLib::poison_new_memory when aligning memory ----------------------+----------------------------------------------------- Reporter: rhaas | Owner: eschnett Type: defect | Status: closed Priority: major | Milestone: Component: Carpet | Version: development version Resolution: invalid | Keywords: ----------------------+----------------------------------------------------- Changes (by rhaas):
* status: review => closed * resolution: => invalid
Comment:
Oh, right. I had apparently not properly checked what the argument to malloc is.
trac@lists.einsteintoolkit.org