I am using VTK together with MSVC and get a strange behaviour when trying to load data. I tinkered a little bit with it and even the following code generates a heap corruption, any ideas what is happening or what possibly went wrong?
vtkAbstractArray *vtkDataReader::ReadArray(const char *dataType, int numTuples, int numComp)
{
char* type=strdup(dataType);
free(type); // <--- here the heap corrution appears
...
This is the call stack:
> msvcr90d.dll!_CrtIsValidHeapPointer(const void * pUserData=0x00691da0) Zeile 2103 C++
msvcr90d.dll!_free_dbg_nolock(void * pUserData=0x00691da0, int nBlockUse=1) Zeile 1317 + 0x9 Bytes C++
msvcr90d.dll!_free_dbg(void * pUserData=0x00691da0, int nBlockUse=1) Zeile 1258 + 0xd Bytes C++
msvcr90d.dll!free(void * pUserData=0x00691da0) Zeile 49 + 0xb Bytes C++
Simulator.exe!vtkDataReader::ReadArray(const char * dataType=0x0370b734, int numTuples=24576, int numComp=3) Zeile 1401 + 0xc Bytes C++
Simulator.exe!vtkDataReader::ReadPoints(vtkPointSet * ps=0x081702d0, int numPts=24576) Zeile 1936 + 0x15 Bytes C++
EDIT:
using this code instead of strdup works nicely, is strdup somehow broken on msvc?
char *type=(char*)malloc(100);
strcpy(type,dataType);
strdup as such is deprecated in msvc and there are reports of similar heap corruption around the web, microsoft states you should use _strdup instead
http://msdn.microsoft.com/en-us/library/ms235454
[EDIT: See below - the real cause seems to be both release and debug versions of the vs runtime dll being loaded, it's just a coincidence that _strdup fixes the problem]