I have a structure:
struct Record {
uint32_t uunused;
uint8_t* data;
uint16_t nRecords;
uint32_t val;
};
Code goes like this: It crashes (seg fault) while freeing the memory. looks like heap is corrupted. but unable to find out the reason. Someone please help it's urgent.
Record *record;
record = (Record *)calloc(1, sizeof(Record)+8)
record->data = (uint8_t *)(record+1);
record->nRecords = 8;
record->val = 0xFFFFFFFF;
uint8_t *var[8];
for(i =0; i< 8; i++)
{
var[i] = &record->data[i]);
}
for(i =0; i< 8; i++)
{
*var[i] = *var[i] + 20;
}
free(record);
User contributions licensed under CC BY-SA 3.0