LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

CVI2010 10.0.1:Combination ListPrealocate ,ListCompact and ListDispose cause runtime error

Solved!
Go to solution

Hi,

    I rebuild od project from CVI7.1.1 in new CVI 2010 10.0.1 and when run i get error " NON-FATAL RUN-TIME ERROR: ... Attempt to free pointer to memory not allocated by malloc() or calloc()."  at source  line with  function call ListDispose(list);

    After some investigation i found that this is in connection with ListPrealocate and ListCompact.

 

   There is simplified sample code:

ListType list=ListCreate(sizeof(int));
ListPreAllocate(list,1);
ListCompact(list);
ListDispose(list);//runtime error at this line
//i also get error when i try call InsertItem after ListCompact

  form toolbox.c it seems to me that problem is in listCompact which free memory but do not update pointer in struct.

 

  i like to have oficial patch for this "bug" to do not have my own version of toolbox.c(because of poslible updates of CVI) and also for other users that can benefit from it.

0 Kudos
Message 1 of 2
(2,938 Views)
Solution
Accepted by topic author OVR_CZ

Hi OVR_CZ,

 

Thank you for bringing this to our attention. I have verified that this is a bug in toolbox.c. I have submitted a bug report (tracking #335805) and it should be resolved in the next release of CVI.

 

Since we provide the source code for toolbox.c, you can actually make the change in your copy yourself. In the ListCompact function in toolbox.c, simply modify the if statement at the bottom of the function as shown below:

 

void CVIFUNC ListCompact (ListType list)
{
    unsigned int tracking;
    void *newPtr = 0;
    
#ifndef TB_NO_SAFETY_CHECKS
    if (!VALIDATE_LIST (list))
        return;
#endif
    list = LIST_GET_POINTER (list);

    if (list->listSize == list->numItems)
        return;
    
#if defined(_NI_mswin_) && _NI_mswin_
    tracking = SetEnableResourceTracking (0);
#endif
    newPtr = realloc(list->itemList, list->numItems * list->itemSize);
#if defined(_NI_mswin_) && _NI_mswin_
    SetEnableResourceTracking (tracking);
#endif
    if (newPtr || list->numItems == 0) {
        list->itemList = newPtr;
        list->listSize = list->numItems;
    }
}

 Note: This may or may not be the change we actually implment for the next release of CVI.

National Instruments
0 Kudos
Message 2 of 2
(2,914 Views)