LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

CVI debugger reports dynamic memory corrupt

Hi,
There is a problem most likely between debugger and CVIXML group of functions.
When I operate even one of CVI examples involving population of tree control out of XML the following function corrupting heap:
                CVIXMLGetElementValue (data,result);

It is important to recognize that even NI example "XMLTree" do not work correctly under debugger (breakpoints and single step).
However if release mode is selected then apparently no problems are noticeable.
Obviously I selected different debugger modes. But no cure found.

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
///// failing example
       {
        char * result;      
        CVIXMLElement data = 0;
        assert(!CVIXMLGetChildElementByTag (column, "Data", &data));
        if (data) {
            int len;
            char * bs;
            CVIXMLGetElementValueLength (data, &len);
            if(len) {
                result=malloc(len+1);
                bs=malloc(1);
                free(bs);
                CVIXMLGetElementValue (data,result);
                bs=malloc(1);
                free(bs);                                 ///////////////// problem right here
                RemoveSurroundingWhiteSpace(result);
                bs=malloc(1);
                free(bs);

      printf("row=%i, column=%i >>>%s<<<\n",j,i,result);   
      free(result);      
            }
        } else (result=""; //empty string (but printable 😉

    }
//.............................

      CVIXMLDiscardElement(data);
      }}



/////////////////////////////////////////////////////////////
/// But if variables are coming from stack then no problem occured.
       {
        char result[100];      
        CVIXMLElement data = 0;
        assert(!CVIXMLGetChildElementByTag (column, "Data", &data));
        if (data) {
            int len;
            char * bs;
            CVIXMLGetElementValueLength (data, &len);
            if(len) {
                bs=malloc(1);
                free(bs);
                CVIXMLGetElementValue (data,result);
                bs=malloc(1);
                free(bs);
                RemoveSurroundingWhiteSpace(result);
                bs=malloc(1);
                free(bs);
            }
        } else result[0]=0; //empty string (but printable 😉

    }
      printf("row=%i, column=%i >>>%s<<<\n",j,i,result);   
      CVIXMLDiscardElement(data);
      }}


Is there any remedy now other than giving up on debugger???

I am using brand new CVI 8.0.1 version and cannot use static data holders..

Otta






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

There is a thread here which may be useful to you.

JR

0 Kudos
Message 2 of 8
(5,642 Views)
Doesn't help,

XMLSample demo working just fine if compiled for release or debug if no breakpoints are set anywhere in the code (debug mode of course). If even one breakpoint is present (and occured) then after this single bkpt everything is "forgotten" panel is empty and even opening file again (without executing this bkpt) do not provide operation on the xml file.

I have clean (only MSDN lib and MS developer studio 2005 installed, plus clean (full) installation of CVI) brand new PC and brand new disk from NI (I should get their help now, we just bought it).
XP SP2.0 Prof.
1GB RAM

And by a way I am CVI veteran for past 10 years. But I never before used CVIXML lib.
Can somebody from NI actually speak?
Otta.
0 Kudos
Message 3 of 8
(5,631 Views)
Hi Otto,

I received your support e-mail and will work with you directly to resolve this issue. I will post to this forum once there is a resolution for others to benefit.

Have a great day,

Ecleamus Ricks, Jr.
National Instruments
Applications Engineer
0 Kudos
Message 4 of 8
(5,603 Views)

It's been 5 years. Apparently this was never resolved?

 

I also get get this error. I am using CVI 2010 which I have found rather buggy. I allocate memory for a structure using "calloc" and at the end of the function I free the memory with "free". Sometimes the "free' gives a fatal error saying dynamic memory is corrupt even though I can view the structure and its contents.

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

Mikie,

 

A bug report regarding this issue was never officially filed because it was never reproduced or identified. Does you have code that produces this error message that you can post here?

National Instruments
0 Kudos
Message 6 of 8
(4,705 Views)

I found that if you write past the allocated size and then try to free the memory, you then get the fatal error.

Message 7 of 8
(4,700 Views)

Mikie,

 

You should never attempt to write past the end of an array when programming in C. In fact you should be getting a fatal run-time error when you attempt to write past the end of an array. This is a feature of CVI that blocks the user from performing such actions which ANSI C does not prevent. What does your code look like that does this? Here is the code I have and as you can see in the comments, I receive the error before I get to freeing the memory.

 

#include <ansi_c.h>

int main (int argc, char *argv[])
{
    int *myArray;
	myArray = malloc(2*sizeof(int));
	*(myArray) = 1;
	*(myArray+1) = 2;
	*(myArray+2) = 3;  //FATAL RUN_TIME ERROR: Dereference of out-of-bounds pointer
	free (myArray);
    
    return 0;
}

 

National Instruments
0 Kudos
Message 8 of 8
(4,686 Views)