LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

Is there a bug in CVI's 'free' function

I've run into a situation were I cannot free my dynamically allocated memory eventhough my pointer in the 'free' call is definitely pointing to the right location. I've written a piece of test code that works when compiled with MSVC, but not with CVI.

Below is a test small, reduced program that demostrates the problem.

This code should be continuously mallocing arrays of ints and then freeing them, but when I compile it with CVI my memory footprint grows continuously. When compiled with MSVC, my memory footprint stays the same, as it should.

When I step through my code with the CVI debugger, the pointer passed to AnyListDeleteItem is pointing to the correct memory location when 'free' is called, but the memory does is not freed.

Is there something I don't understand about dynamic memory allocation or is this a bug?

Regards,
Greg VanSlyke

#include
#include
#include

static int panelHandle;
void* AnyListAddItem(void** list, int size);
int AnyListCreate(void** list);
int AnyListDelete(void** list) ;
int AnyListDeleteItem(void** list, void* item);


AnyListCreate(void** list)
{
*list = NULL;
return 0;
}

void* AnyListAddItem(void** list, int size)
{

*list =(void*)malloc(size);
return *list;
}
int AnyListDeleteItem(void** list, void* item)
{
free(item);
return 0;
}

int main (int argc, char *argv[])
{

int *any_list;
int *list_item1;

if (InitCVIRTE (0, argv, 0) == 0)
return -1; /* out of memory */
if ((panelHandle = LoadPanel (0, "test.uir", PANEL)) 0)
return -1;
DisplayPanel (panelHandle);


AnyListCreate((void**)&any_list);
while(1)
{
list_item1 = (int*)AnyListAddItem((void**)&any_list,100*sizeof(int));
AnyListDeleteItem((void**)&any_list,list_item1);
}
RunUserInterface ();
DiscardPanel (panelHandle);
return 0;
}
0 Kudos
Message 1 of 2
(2,929 Views)
Hello

I looked into this some more and the free and malloc functions are working fine. I used CVIDynamicMemoryInfo to make sure the blocks were being allocated and released correctly. I noticed i didnt get the leak when i changed the debugging level to disable run-time checking ( Options >> Build Options >> Debugging Options section.). But it looks like it might be a problem with the way we are tracking some run-time debugging information. This problem should not happen with release builds of the application.

I'll file a report with R&D to investigate this issue some more.
Bilal Durrani
NI
0 Kudos
Message 2 of 2
(2,897 Views)