## Spot the leak! Programming Challenge!!!

Here's a fun one. This program has a memory leak. See if you can find it!

I had a much larger program with this same memory problem in it, took me a good deal of time and a half a 2 liter of mountain dew to figure it out...

Code:
```#include <iostream>
using namespace std;

struct Thing
{
int *deally;     // used for a dynamic array if integers.
int deallysize;  // something to keep track of the array size.
};

int main()
{
int thingCount = 10;
Thing things [thingCount];
for (int i=0; i<thingCount; i++)
{
things [i].deallysize = i+1;
things [i].deally = new int [i+1];
things [i].deally [0] = 100 + i;
}

// Print things-
for (int i=0; i<thingCount; i++)
cout << "thing# " << i << " = " << things [i].deally [0] << endl;

/// Remove element x from the list.
/// Instead of leaving the space
/// empty, replace it with the last
/// element.
int x = 4;

cout << endl;
cout << "removing element " << x << " and replacing with last" << endl;
cout << endl;

thingCount--;                              // thingCount has decreased by one.
things [x] = things [thingCount];          // replace element x with the last element.

/// delete the last element
things [thingCount].deallysize = 0;        // set the size of the array to zero.
if (things [thingCount].deally !=0)        // check if the array exists.
{
delete [] things [thingCount].deally;  // if it does, delete the array.
things [thingCount].deally = 0;        // and set the pointer to zero.
}

// Print things-
for (int i=0; i<thingCount; i++)
cout << "thing# " << i << " = " << things [i].deally [0] << endl;

/// delete the remaining elements in the array before exiting
for (int i=0; i<thingCount; i++)
{
things [i].deallysize = 0;
if (things [i].deally != 0)
{
delete [] things [i].deally;
things [i].deally = 0;

}
}

cin.get ();
return 0;
}```
K, it might be obvious to anybody familiar with pointers and memory allocation, but I'll bet a few of you have done the same thing sometime or another! Please, post a solution and let me know how quick you figured it out! :D