LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

When I add list to a data chain, the address of the previous pointer is changed and of couse I get a error while free it

The struct of the chain  as follows:

typedef struct _SHOW_DATA
{

    int GainStates;  
    int ShowDataIsValid;
    struct _SHOW_DATA *pNext;
}SHOW_DATA;
typedef struct _DATA_CHAIN
{
 SHOW_DATA *pStart;
 SHOW_DATA *pWrite;
}DATA_CHAIN;

Add list function:

void DataChain_Add(DATA_CHAIN *pChain,SHOW_DATA *pshowData)
{
 if(pChain->pStart == NULL)
 {
  pChain->pStart = pshowData;
  pChain->pWrite = pshowData; 
  FirstDataIn = TRUE;  
 }
 else
 {
  pChain->pWrite->pNext = pshowData;
  pChain->pWrite = pChain->pWrite->pNext;
 }

}
pStart saves the starting pointer of the chain,pWrite pointer the end of the chain,using pshowData=malloc(sizeof(SHOW_DATA))  to add list 。When the list is not to long,pStart->pNext== 0x00FF3C20;the address is true,but as the list is longer,suddenly the address is changed,becomes 0x0000001E. So when I delete list,free the address 0x0000001E, of course I got a Error “attempt to free pointer to memory not allocated by malloc() or calloc()”.Who can help me?Thank you!!!

Download All
0 Kudos
Message 1 of 4
(3,189 Views)

Hi,

 

please could you point out in how far this question is related to CVI? This is not a forum about the programming language C...Smiley Wink

0 Kudos
Message 2 of 4
(3,184 Views)

by the way, there NO need for multiple posts 

0 Kudos
Message 3 of 4
(3,181 Views)

I am so sorry, I thought I Posted in the Chinese section cannot being seen in the English section.

I think it is the bug of  labwindows 2009,so I posted this question here. however ,I will continue to research this question

0 Kudos
Message 4 of 4
(3,175 Views)