JSONKit
JSONKit copied to clipboard
analyzer warnings
There are two "Memory is never released" warnings (analyzed with Xcode 4.5 (4G144l))
Also in the GM (4G182)
Same problem
Same here with the Release XCode 4.5 (4G182) Version!
I tried adding NS_RETURNS_RETAINED to the function headers, the static analyzer still complains.
The two warnings are here:
- https://github.com/johnezang/JSONKit/blob/82157634ca0ca5b6a4a67a194dd11f15d9b72835/JSONKit.m#L682
- https://github.com/johnezang/JSONKit/blob/82157634ca0ca5b6a4a67a194dd11f15d9b72835/JSONKit.m#L933
I got a message from Shazron and I finally had time to take a look.
In both cases: It's a manual calloc and then the pointer gets reassigned via the instance init method. So that's why the analyzer complains about memory leaks.
I have updated my fork of this library and I think this is the solution: https://github.com/GlennChiu/JSONKit/commit/2570575ac4dec7878bd2795a97b6964b0d2aed49
I have not tested the code yet, but let me know if it works.
addition of those two lines crashed for me....
crashed for me too
GlennChiu's patch is incorrect - you can't free the memory there because in the next line the "init" message is sent to it (that's why it crashes).
I finally had more time to look into it. I've tested it in my unit tests and they seem to work fine. Inspect my changes: https://github.com/shazron/JSONKit/commit/5c330695e8b689e6ffb5b79db23cb630b0e921f8
I inspected https://github.com/shazron/JSONKit/commit/5c330695e8b689e6ffb5b79db23cb630b0e921f8 -- please see my comments there.
I feel quite embarrassed about my proposed solution. I should've known better.
I have been thinking about making it a regular alloc/init call as well, just like pianofab suggests: https://github.com/GlennChiu/JSONKit/commit/ce2db0cadeb7bd3fdefdcaa9c26f5cda17de9166
What I don't really understand is why the analyzer is complaining about calloc
but not something like class_createInstance
(which is basically the same if I'm not mistaken).
Hello all...I see there hasn't been much movement on this, but I wanted to voice a very loud +1 to getting this issue fixed. I'd be happy to converse with the developers, and do whatever possible to get this fixed in the main branch. I can fix it myself I suppose, but I'd rather not branch from the main, considering I've used JSONKit a number of different times. Please feel free to contact me -- I'd love to get a fix for this ASAP. Thx for a great library. [email protected]
Does it make sense tho? I mean, if the ptr is NULL, free
is a NOOP, so technically the analyzer is being over-zealous about standards.
+1
+1
This fork has a nice fix: https://github.com/apptentive/PrefixedJSONKit/commit/2d97fd941bc6f3eac711c9c4256a830fd1fb9f25
Got another one a little later on in the dictionary create function but it clears up the warnings from two to one.
Really nice @Bo98 ! Thank you for the link.
Has there been any traction on the dictionary create function? The fix at 2d97fd941bc6f3eac711c9c4256a830fd1fb9f25 for the JKDictionaryCreate doesn't seem to change anything
Yeah, the dictionary create function is still moaning. I'll see if I can do anything about that.
Check this out, for the dictionary create, this is a gist from one of the fixes in this thread
https://gist.github.com/absessive/6286930
A better fix is also at http://stackoverflow.com/a/16731989/717216