I am using a c lib in my iPhone application. The c lib is written by someone I do not have access to.
However I am getting the error that object 0xa6000d is being freed but not allocated. The debug variable screenshot is here.

struct GtsMsg is defined as,
struct msg {
int offset;
int dataLength;
u8* data;
cBool expandable;
cBool owned;
u8* mid2key;
};
#define GtsMsg struct msg
void freeMessageData(GtsMsg* msg) {
if (msg == NULL) return;
if (msg->owned) {
if (msg->data != NULL) {
free(msg->data);
}
}
free(msg->mid2key);
memset(msg, 0, sizeof(GtsMsg));
}
The breakpoint for malloc_error_break is the line free(msg->data).
I have added the checking if (msg->data != NULL), but it did not work. What are the ways to check if the memory for msg->data or for msg is allocated or not?
Do you think there is something fishy, at *data = (u8)’\0′?
thanks in advance!
Thanks to all to your suggestions.
Thanks hmjd for your tips.
I found the struct is used in a cpp class which destructor calls the freeMessageData. But I could not find that the struct is initialized. So, if I initialize the struct to NULL in the declaration, this avoid the free memory problem and do not crash.
Its something suggested by simonc. If he writes that as an answer not, comment, I could accept that.
From comments of
hmjd,