LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

Ini_GetStringIntoBuffer generates "General Protection" Fault

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:

 

Ini_GetPointerToString.jpg

 

Here you can see the valid pointer for the destination. However after stepping into the Unescape function, it changes.

 

UnescapeText.jpg

 

What the heck is going on here?

0 Kudos
Message 1 of 8
(5,839 Views)

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.



Proud to use LW/CVI from 3.1 on.

My contributions to the Developer Community
________________________________________
If I have helped you, why not giving me a kudos?
0 Kudos
Message 2 of 8
(5,836 Views)

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..

 

Ini_GetPointerToString - dest working.jpg

 

dest->stringCache is being passed and it is 0x037E1450. It is pointing to 0x037E26B0.

 

The next time through, actually reading the same file.

 

Ini_GetPointerToString - dest failing.jpg

 

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;

 

 

 

 

0 Kudos
Message 3 of 8
(5,829 Views)

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.

0 Kudos
Message 4 of 8
(5,827 Views)

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.

0 Kudos
Message 5 of 8
(5,820 Views)

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?

0 Kudos
Message 6 of 8
(5,738 Views)

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

0 Kudos
Message 7 of 8
(5,713 Views)

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.

0 Kudos
Message 8 of 8
(5,700 Views)