You are writing beyond the end of the buffer here:
pBuff[fSize] = '\0';
Your call to delete
is wrong. It needs to match the call to new
.
delete[] pBuff;
Personally I don't see why you would use raw memory allocations here. Wouldn't it be better to use a standard container, std::vector<unsigned char>
in this case. Or if for some reason you have to use raw memory allocation then at least wrap the memory up in a smart pointer.
You say that after fixing these problems, your code still fails of the delete
. That sounds like you have corrupted the heap elsewhere.