CarpetLib::poison_new_memory when aligning memory

Create issue
Issue #1432 closed
Roland Haas created an issue

looking at the poison code in CarpetLib's it seems to me that the poisoning cdoe uses the wrong data pointer ie uses line 144 of

    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).


Comments (4)

  1. Erik Schnetter
    • 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.

  2. Log in to comment