dynamic array in recursion with different compiler
<p>I write it to count the inversion of number and I run it fine in <code>gcc version 4.2.1 20070831 patched</code> but when I run it on codeblock  using <code>mingw32</code> it close accidently. </p>

<p>I debug and find it was in the <code>int *left = new int[middle];int *right = new int[length - middle];</code> but <code>it just come to error when it recursive on second time</code>,and I don't know why it cause error and don't know how to fix it.</p>

<p>My questions are </p>

<p>1.How to fix the error?</p>

<p>2.Is there any other heap lost I didn't delete, because I am not sure just want to check it.</p>

<p>Thx in advance.</p>

<pre><code>#include&lt;iostream&gt;
using namespace std;
int invCount(int*, int);
int merge(int*, int*, int, int*, int);
int main(void){
    int array[] = {0, 1, 4, 3, 2};
    cout &lt;&lt; invCount(array, 5) &lt;&lt; "times" &lt;&lt; endl;
    return 0;
}
int invCount(int *array, int length){
    cout &lt;&lt; "length:" &lt;&lt; length &lt;&lt; endl;

    if(length &lt;= 1){
            return 0;
    }

    int middle = (length + 1) / 2;

    cout &lt;&lt; length &lt;&lt; endl &lt;&lt; middle &lt;&lt; endl &lt;&lt; length - middle &lt;&lt; endl;
    cout &lt;&lt; endl;

    int *left = new int[middle];
    int *right = new int[length - middle];


    for(int i = 0; i &lt; middle; i ++)left[i] = array[i];//error
    for(int i = middle; i &lt; length; i ++)right[i] = array[i];//error

    return invCount(left, middle) + invCount(right, length - middle
    ) + merge(array, left, middle, right, length - middle);
}

int merge(int* array, int* left, int leftLength, int* right, int rightLength){
   int i = 0, j = 0, count = 0;

   while(i &lt; leftLength || j &lt; rightLength){
       if(i == leftLength){
           array[i + j] = right[j];
           j ++;
       }
       else if(j == rightLength){
           array[i + j] = left[i];
           i ++;
       }
       else if (left[i] &lt;= right[j]){
           array[i + j] = left[i];
           i ++;
       }
       else {
           array[i + j] = right[j];
           j ++;
           count += leftLength - i;
       }
   }
   delete[] left;
   delete[] right;
   return count;
}
</code></pre>
