Having trouble deallocating a multidimesnional dynamic array of pointers.

What I have is a pointer to an array of pointers to arrays of pointers.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
// global
int*** pppInt;

void allocate()
{
	pppInt = new int**[10];
	for(int i = 0; i < 10; i++)
	{
		pppInt[i] = new int*[20];
		for(int j = 0; j < 20; j++)
		{
			pppInt[i][j] = NULL;
		}
	}
}

void deallocate()
{
	for(int i = 0; i < 10; i++)
	{
		for(int j = 0; j < 20; j++)
		{
			if(pppInt[i][j] != NULL)
			{
				delete pppInt[i][j];
				pppInt[i][j] = NULL;
			}
		}
		delete[] pppInt[i];  // runtime error here
		pppInt[i] = NULL;
	}
	delete[] pppInt;
}

Now correct me if i'm wrong, but all the line of code I flagged is doing is trying to deallocate a dynamic array of int pointers. The index gives you a valid int**.

I am using VC++ 2008 express. The message is about a failed debug assertion as says: _BLOCK_TYPE_IS_VALID(pHead->nBlockUse)

Dunno if that helps. But could this maybe be something screwy with VC++? I don't see how my syntax is erroneus.

But still, even if this is supposed to work, am I actually deallocating everything properly or am I leaking something?
Last edited on
Topic archived. No new replies allowed.