I have a function like
char *mdb_data = NULL;
int mdb_dataLen = 0;
char *getMDBDataPtr(int len)
{
if(len <= 0)
return NULL;
if(mdb_data == NULL)
{
mdb_data = (char *)malloc(len);
memset(mdb_data, 0, len);
mdb_dataLen = len;
}
else
{
if(mdb_dataLen < len)
{
free(mdb_data);
mdb_data=NULL;
mdb_data = (char *)malloc(len);
memset(mdb_data, 0, len);
mdb_dataLen = len;
}
}
return mdb_data;
}
When this function is called once i.e mdb_data=NULL it works. Afterwards when I called it with length 1 , 2 , 3 it failed when freeing memory for 3rd case i.e it free works fine twice and the crashes the application. Any ideas why this might be happening ?