Well, there is a better way to do it, it's always best to allocate memory that goes together all at once. Remember, using a C-cast you can change anything into anything else.
Code:
int** array = (int**)malloc(width * height * sizeof(int));
Then to delete it simply:

Looking at your code at a quick glance, I don't see anything incorrect. I would run it through the debugger and put a breakpoint on each delete[] 
Also, it's good practice to explicity declare what type you're using.
Code:
unsigned n = 0; //not standard C++
unsigned int n = 0; //correct
Bookmarks