It seems to me that you are trying to free a stack or a static variable. You need to have malloc () 'd so that it can be free ()' d.
Try this instead:
TestStruct *ts = malloc(sizeof(TestStruct)); ts->value = 33; free(ts);
For those who are more familiar with object-oriented languages, it might be useful to create a constructor:
TestStruct *newTestStruct(int value) { TestStruct *ret = malloc(sizeof(TestStruct)); ret->value = value; return ret; }
This allows you to highlight the structure and set values โโin one step. Just remember that this value should be freed when it is no longer useful:
TestStruct *x = newTestStruct(3); free(x);
source share