07-09-2014 08:29 AM
During a subsequent call to Ini_GetStringIntoBuffer, I get a "General Protection" fault.
Ini files are opened and closed previous to this call. The current file has already been opened and several properties have already been successfully read and stored. The fault is ocurring when the "UnescapeText" function is called. The destination pointer is in invalid memory and crashes when it is incremented. The pointer is valid when entering the function however. See below:
Here you can see the valid pointer for the destination. However after stepping into the Unescape function, it changes.
What the heck is going on here?
07-09-2014 08:46 AM
In my opinion the changing in the memory address is regular: in the first image you are pointing to dest, in the second you are seeing dest->stringCache address.
IniFile instrument is active from several CVI releases, in my opinion it is robust and not prone to errors, at least not so severe errors: can you show the relevant part of your code where the error arises? Maybe some particular sequence of instructions makes the instrument crash for some reason, but as far as I can tell from my experience problems are normally in the outer code and not in the instrument itself.
07-09-2014 10:14 AM - edited 07-09-2014 10:15 AM
I'm sure the ini library is pretty robust. I've been using it for almost a decade now.
Aren't destTextPtr, and dest->stringCache supposed to be the same? The pointer, stringCache is what is supposed to be passed in. The called function can call it anything it wants, it just happens to call it destTextPtr.
The previous time the same file is opened and interregated, the function is working fine..
dest->stringCache is being passed and it is 0x037E1450. It is pointing to 0x037E26B0.
The next time through, actually reading the same file.
dest->stringCache is being passed and it is 0x037E1450. It is pointing to 0x40C00000.
The calling code:
if (Method_IniFile)
Ini_Dispose(Method_IniFile);
Method_IniFile = Ini_New (0);
MODEL_DUT *Model = (MODEL_DUT*)gpModel;
// Read INI File
iAux = Ini_ReadFromFile (Method_IniFile, sFullFileName);
if (iAux)
{
sprintf(sErrorText, "%s: The INI File doesn't exist or is not valid.", sFullFileName);
Ini_Dispose(Method_IniFile);
Method_IniFile = 0;
return iAux;
}
strcpy (gpMethodFileName, sFullFileName);
strcpy (sMoMethodFile, sFullFileName);
//=============================================================
// Read PROPERTIES Section
//=============================================================
strcpy(sSectionName, "PROPERTIES");
if (Ini_SectionExists (Method_IniFile, sSectionName))
{
SNIP
// Get the Actuator Name
iStatus = Ini_GetStringIntoBuffer (Method_IniFile, sSectionName, "ActuatorName", sItemValue, 64);
SNIP
}
Ini_Dispose(Method_IniFile);
Method_IniFile = 0;
07-09-2014 10:25 AM
I see it's being passed in to the original function as Method_IniFile. It is probably corrupt going in. It is used successfully a number of times before this particular call so I'll have to track down where it changes.
07-09-2014 01:59 PM
Apparently, the memory allocated by the ini library function SetStringCacheSize in the Ini_GetPointerToString function has already been allocated to one of my structure arrays. The offending line in Ini_GetPointerToString:
errChk(SetStringCacheSize(dest->stringCache, (int)strlen(rawString)+1));
The function itself:
if (!SetHandleSize((void **)strHandle, numCacheChunks * kStringCacheChunkSize))
My structure is allocated as below in my code:
*pTest = (TTEST*) calloc(iNumberOfControls, sizeof(TTEST));
dest->stringCache and my float are both allocated to 0x3961450.
07-21-2014 10:18 AM - edited 07-21-2014 10:20 AM
The ini library function SetStringCacheSize() is overwriting memory in previously allocated memory. This memory has not been released and should be protected.
I was hoping that after a week's vacation, there might have been a response. Why is SetHandleSize((void **)strHandle, numCacheChunks * kStringCacheChunkSize) allocating memory that has already been allocated?
07-22-2014 07:44 PM
Hi mikie,
Could you try replicating this issue in a short piece of code and posting it here? It might make it easier for people to understand and help troubleshoot your issue.
Myriam
07-23-2014 07:00 AM - edited 07-23-2014 07:01 AM
I haven't found root cause, but I'm closer at understanding the condition.
I pass a structure in by value and a copy is made. This copy is what the SetStringCacheSize() function is overwriting. I can eliminate the proplem by passing in a structure by reference, but it does not fix the root problem. It is just a workaround.