Is JSONKit for creating memory leaks?

I use JSONKit in my application, but now that I have upgraded to Xcode 4.5.1 and started the analysis, Xcode reports possible memory leaks in the JSONKit code.

/Users/aleksa.topic/SVN/Apple/iTTChart/trunk/iTTChart/Other Sources/JSONKit.m:682:23: Memory is never released; potential leak of memory pointed to by 'array' /Users/aleksa.topic/SVN/Apple/iTTChart/trunk/iTTChart/Other Sources/JSONKit.m:682:23: Memory is never released; potential leak of memory pointed to by 'array' (and this gives the same potential leak for the dictionary).

Does anyone have any experience with this? Does this really create memory leaks, or is it just that Xcode does not analyze enough?

+4
source share
3 answers

This is a false positive value in a static analyzer. There, an error report tries to solve it.

+4
source

See the link. Just replace the lines marked as - with a + mark.

 - if((array = [array init]) == NULL) { return(NULL); } + if([array init] == NULL) { free(array); return(NULL); } 

 - if(JK_EXPECT_F((array->objects = (id *)malloc(sizeof(id) * array->capacity)) == NULL)) { [array autorelease]; return(NULL); } + if(JK_EXPECT_F((array->objects = (id *)malloc(sizeof(id) * array->capacity)) == NULL)) { free(array); return(NULL); } 

 - if((dictionary = [dictionary init]) == NULL) { return(NULL); } + if([dictionary init] == NULL) { free(dictionary);return(NULL); } 

 - if(JK_EXPECT_F((dictionary->entry = (JKHashTableEntry *)calloc(1UL, sizeof(JKHashTableEntry) * dictionary->capacity)) == NULL)) { [dictionary autorelease]; return(NULL); } + if(JK_EXPECT_F((dictionary->entry = (JKHashTableEntry *)calloc(1UL, sizeof(JKHashTableEntry) * dictionary->capacity)) == NULL)) { free(dictionary); return(NULL); } 
+2
source

Replace ((array = [array init]) == NULL) with (dictionary == NULL) and use free(array) instead of [array autorelease] to fix this. Because he cursed manually, so that he would also be released manually.

+1
source

Source: https://habr.com/ru/post/1442798/


All Articles