NI Home
Cart Cart | Help
Hello Events Academic NI Developer Zone Support Solutions Products & Services Contact NI MyNI
You are here: 
NI Home > NI Developer Zone > NI Discussion Forums


Reply
Member
OVR_CZ
Posts: 91
0 Kudos
Accepted Solution

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

[ Edited ]

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.

Active Participant
D_Biel
Posts: 640
0 Kudos

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

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
Product Support Engineer
By using this web site, you accept the Terms of Use for this web site. Please read these Terms of Use carefully before using any part of this site. Please go here for information on ni.com's copyright infringement policy.
My Profile | Privacy | Legal | Contact NI © 2011 National Instruments Corporation. All rights reserved.    |    E-Mail this Page E-Mail this Page