Fix off-by-one bug in reporting memory allocation

This also makes the update volatile to prevent reordering