LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

CVI hang when release memory, how to debug?

Building a CVI dll.  When called, 1st time run ok; CVI hang on the 2nd called.

Hang on free().

The memory is dynamically allocated for an array of int.

There are several dynamically allocated memory blocks.

Always hang on the same one.  the first free().

 

How to find the problem?

 

George Zou
0 Kudos
Message 1 of 7
(4,154 Views)

Hey zou,

 

I just have a few questions about your testing methods, specifically how you are calling the DLL. Is it the same function you call each time that the DLL hangs on or is it multiple functions? Can you try making a simple DLL with a single function that allocates memory and then free()s it? Lastly, are you using malloc to dynamically allocate the memory?

 

Best Regards,

 

-KP

Kurt P
Automated Test Software R&D
0 Kudos
Message 2 of 7
(4,127 Views)

Thanks for reply.

There is only one function exported from the dll.

The dll is called in LabVIEW.

CVI hang even the caller VI closed after the first call.

The only way to avoid hang is to exit LabVIEW completely.

This particular pointer is allocated by malloc.  There are others allocated GlobalAllocate.

Can't create a simply dll.  Doesn't service the purpose for this project.

 

function prototype:

int __stdcall Element(char *xml, char *output, int length, HBITMAP *hBitmap);

 

xml: input xml string.

output: output xml string.  Memory allocated by the caller.

length: output buffer size.

hBitmap: fixed length array of int.  Memory allocated by the caller.

 

 

George Zou
0 Kudos
Message 3 of 7
(4,118 Views)

Hey zou,

 

This could happen because you are not releasing the DLL from memory.

 

How are you determining that the DLL freezes on free()?

Is the DLL debugable? Try making it as release and see if it still freezes there. 

 

You can try to dynamically load and unload the DLL to make sure it is out of LabVIEW's memory. This KnowledgeBase goes over how to do that:

 

http://digital.ni.com/public.nsf/allkb/77594203D78D12278625729100758BE5?OpenDocument

Kurt P
Automated Test Software R&D
Message 4 of 7
(4,090 Views)

Kurt,

 

Thanks for reply.

 

> This could happen because you are not releasing the DLL from memory.

I closed the calling VI.  LabVIEW should release the dll.

 

> How are you determining that the DLL freezes on free()?

> Is the DLL debugable? Try making it as release and see if it still freezes there. 

The dll is debugable.  I attached CVI to LabVIEW to run the debug.

I traced to the free() function.  CVI hangs.

I already tried release version. No difference.

 

I'll try to dynamically load / unload the dll in LabVIEW.

 

More information, just found today when I turned on build options => debuging level.

Go 2 non-fatal run time error.  One in cvixml.c (the 2009 version) when free a string pointer;

one in my code when free another string pointer.

The error message indicated that try to free a pointer which is not allocated by malloc or calloc.

When click ignor on the error dialog window, CVI no longer hang.  It returns to LabVIEW without problem

on the 2nd times.

That's strange because I allocated the memory for the xml string using malloc!

When I change to CA_FreeMemory, only one non-fatal error.

These xml string is total un-related to the free() which locks up CVI.

 

I'm using CVI 2012.

I'm still using the old cvixml.c because I modified it a couple years ago with the help of NI AE.

So that I can create an xmldoc from a string, instead of a file in CVIXMLLoadDocument().

 

 

George Zou
0 Kudos
Message 5 of 7
(4,088 Views)

Tried dynamically load / unload the dll.  Still hang.

 

 

George Zou
0 Kudos
Message 6 of 7
(4,080 Views)

Hey George,

 

I noticed that you are working with another applications engineer on this issue. Ian and I will continue to work with you through that service request you created. 

 

Thank You,

 

-KP

Kurt P
Automated Test Software R&D
0 Kudos
Message 7 of 7
(4,068 Views)