i have the following struct:
typedef struct {
char* type;
char* address;
int area, price;
}Offer;
and these two functions:
Offer* initOffer(char* type, char* address, int area, int price)
{
Offer* p;
p = (Offer*)malloc(sizeof(Offer));
p->type = (char*)malloc(sizeof(type));
p->address = (char*)malloc(sizeof(address));
strcpy(p->type, type);
strcpy(p->address, address);
p->area = area;
p->price = price;
return p;
}
void destroyOffer(Offer* offer)
{
free(offer->type);
free(offer->address);
free(offer);
}
The problem occurs when i call destroyOffer, I have no idea why, but when I run the code, I have an error saying: HEAP CORRUPTION DETECTED. If i remove these 2 lines, it works fine but I suppose that the memory is not cleaned properly:
free(offer->type);
free(offer->address);