I have this simple example which fails in "delete poinerToBufferPointer":
char* buffer = new char[8];
memset(buffer, 1, 8);
char** poinerToBufferPointer = &buffer;
delete poinerToBufferPointer;
delete[] buffer;
But if I comment the "delete poinerToBufferPointer"
char* buffer = new char[8];
memset(buffer, 1, 8);
char** poinerToBufferPointer = &buffer;
//delete poinerToBufferPointer;
delete[] buffer;
it's working but the question is who will delete the double pointer?
Also very strange behavior is when I do delete on the pointer only it fail on delete[]
buffer.
char* buffer = new char[8];
memset(buffer, 1, 8);
char** poinerToBufferPointer = &buffer;
delete *poinerToBufferPointer; // <--- only delete the pointer that points
delete[] buffer;
What is going on in memory, and what is the right way to delete both pointers?