当我在这部分代码中释放内存时......我收到一个错误,显示为 :free(): invalid next size (fast)
int insertRecord(char *record,int recordSize,long dataPageNumber)
{
datapage *dataPage=(datapage *)malloc(sizeof(datapage));
readPage(dataPage,dataPageNumber);
slotentry slot;
//for checking and freeslotnumber storage
int freeSlotNumber=-1;
int negativeFlag=0;
int freeFlag=0;
if(recordSize+sizeof(slotentry)<=dataPage->cfs)
{
slot.slotsize = recordSize;
slot.slotaddress = dataPage->cfsptr;
dataPage->cfs -= (recordSize+sizeof(slotentry));
dataPage->cfsptr += recordSize;
dataPage->slotcount++;
memcpy(&dataPage->data[slot.slotaddress],record,recordSize);
free(dataPage);
return 1;
}
执行 free(dataPage) 后,我收到上述错误...
typedef struct
{
int pagenumber;
int priority;
long dirPageNo;
long cfs;
int cfsptr;
int slotcount;
char data[1];
} datapage;
typedef struct
{
int slotaddress;
int slotsize;
} slotentry;
我在 memcpy 之前保留了 free(dataPage) 它工作正常,但在 memcpy 之后它不工作..并显示错误....任何人都可以帮助我解决这个问题...