Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

potential leak of memory #145

Open
willonboy opened this issue Nov 21, 2013 · 0 comments
Open

potential leak of memory #145

willonboy opened this issue Nov 21, 2013 · 0 comments

Comments

@willonboy
Copy link

static JKArray *_JKArrayCreate(id *objects, NSUInteger count, BOOL mutableCollection) {
NSCParameterAssert((objects != NULL) && (_JKArrayClass != NULL) && (_JKArrayInstanceSize > 0UL));
JKArray *array = NULL;
if(JK_EXPECT_T((array = (JKArray *)calloc(1UL, _JKArrayInstanceSize)) != NULL)) { // Directly allocate the JKArray instance via calloc.
object_setClass(array, _JKArrayClass);
if((array = [array init]) == NULL) { return(NULL); }
array->capacity = count;
array->count = count;
if(JK_EXPECT_F((array->objects = (id *)malloc(sizeof(id) * array->capacity)) == NULL)) { [array autorelease]; return(NULL); }
memcpy(array->objects, objects, array->capacity * sizeof(id));
array->mutations = (mutableCollection == NO) ? 0UL : 1UL;
}
return(array);
}

JSONKit.m:682:23: Memory is never released; potential leak of memory pointed to by 'array'

AND

static JKDictionary *_JKDictionaryCreate(id *keys, NSUInteger *keyHashes, id *objects, NSUInteger count, BOOL mutableCollection) {
NSCParameterAssert((keys != NULL) && (keyHashes != NULL) && (objects != NULL) && (_JKDictionaryClass != NULL) && (_JKDictionaryInstanceSize > 0UL));
JKDictionary *dictionary = NULL;
if(JK_EXPECT_T((dictionary = (JKDictionary *)calloc(1UL, _JKDictionaryInstanceSize)) != NULL)) { // Directly allocate the JKDictionary instance via calloc.
object_setClass(dictionary, _JKDictionaryClass);
if((dictionary = [dictionary init]) == NULL) { return(NULL); }
dictionary->capacity = _JKDictionaryCapacityForCount(count);
dictionary->count = 0UL;

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

NSUInteger idx = 0UL;
for(idx = 0UL; idx < count; idx++) { _JKDictionaryAddObject(dictionary, keyHashes[idx], keys[idx], objects[idx]); }

dictionary->mutations = (mutableCollection == NO) ? 0UL : 1UL;

}
return(dictionary);
}

JSONKit.m:933:58: Memory is never released; potential leak of memory pointed to by 'dictionary'

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant