The way you're using sizeof()
is incorrect. It's returning the size of the pointer, not the size of the pointed-to thing. There is no way to access the size of the pointed-to thing given just its pointer when you're pointing to an array of items.
You'll have to remember the size you allocated with new
somewhere and use that.