NI TestStand

cancel
Showing results for 
Search instead for 
Did you mean: 

Suspected Memory Leak from CVI

Hi,
I am calling a function from a DLL created by CVI/Labwindows in TestStand. When I run this function couple of times the PC crashes and believe it is something to do with memory leaks. I am freeing the memory of local variables created in CVI, but there is a string returned to one of the parameters from my function in CVI to TestStand.
I have look at this document that hints about memory leak between CVI and TestStand:
 
But I am not sure how can I do that in my function as I need the argument returned to teststand.
Attched is my CVI function and Test Stand file.
Does any body have any idea how to prevent this...
 
Thanks
mama007
 
Download All
0 Kudos
Message 1 of 5
(3,280 Views)
Hi
As you do not use any TestStand API function in your code they cannot be the reason for the crash(es).
Your DLL takes a parameter "char Data[750]" but your function body does not care about the length it might get: Instead you use strcat() without doing any length checks. Maybe you exceed with these strcat operations the your string's memory?  That would be a good candidate for your problem.
Regards, Guenter
0 Kudos
Message 2 of 5
(3,271 Views)
Hi Guenter,
The document 2MRBTCY6 tells Test Stand allocates new memory to pass/receive information from/to CVI.
I suspect if this is not cleared, it can cause memory leak. I am not right?
 
I am using  char Data[750] for returning information back. The function already returns a value,which in my case number of events and I also want to pass the data back as well. Thats why I used this as a return argument.
So you can assume Data[750] does have blank/garbage in it when passed,and filled with actuval data I need when the funtion is finished.
 
Thanks
mama007
0 Kudos
Message 3 of 5
(3,262 Views)

Hi,

I have checked again and thinking it might not be memory leak between Teststand and CVI, instead memory leaks in CVI itself.

I have modified this function to the following simple call. and when I run this function many times, I didn't have any problems.

int _stdcall _export readserialport(int COM_Port,char COM_Data[500])
{

 int n=0;

 n = ComRdTerm (COM_Port,COM_Data,500,00);  // 00 -Event Termination byte

 return n;

}

But when I have added the line COM_Data=strcat(COM_Data,"end"); before return, Teststand crashed.

I feel the memory leak is the way the function strcat() works; ANy body have any clues...

0 Kudos
Message 4 of 5
(3,254 Views)
Are you using TestStand 3.5?  If so, turn on your debug options that check for memory corruption.  It appears you are using strcat to add to a string without checking the bounds of it.  You very well could be going over the 750 byte buffer you create when calling the function.

Allen P.
NI
0 Kudos
Message 5 of 5
(3,238 Views)