After taking a quick look at the documentation, you should call the function giGetIndexedMesh twice. First, to retrieve the required sizes (vcount and icount) by setting the last parameter to NULL. And the second time to retrieve the indices.
In your code snippet, you allocate the array using an old value of icount. The required value is determined later, but you must determine it before: