I'm looking for an annotation something like
-(SomeStruct *) structFromInternals __attribute__((returns_malloced_ptr)) { SomeStruct *ret = malloc(sizeof(SomeStruct));
to reassure the beast of a static clan analyzer. The only viable link I can find is for GCC , but it doesn't even include ns_returns_retained , which is in the extension, I suppose.
EDIT:
why it is necessary, I have a script that I can not reproduce in the simple case, so it can be related to ac lib in the Objective-C project ... The bottom line is that I get a static analyzer that warns about the leak of malloc in createStruct:
typedef struct{ void * data; size_t len; }MyStruct; void destroyStruct(MyStruct * s) { if (s && s->data) { free(s->data); } if (s) { free(s); } } MyStruct * createStructNoCopy(size_t len, void * data) { MyStruct * retStruct = malloc(sizeof(MyStruct)); retStruct->len = len; retStruct->data = data; return retStruct; } MyStruct * createStruct(size_t len, void * data) { char * tmpData = malloc(len); memcpy(tmpData, data, len); return createStructNoCopy(len, tmpData); } MyStruct * copyStruct(MyStruct * s) { return createStruct(s->len, s->data); }
source share