JSONKit icon indicating copy to clipboard operation
JSONKit copied to clipboard

analyzer warnings

Open benrudhart opened this issue 12 years ago • 20 comments

There are two "Memory is never released" warnings (analyzed with Xcode 4.5 (4G144l))

benrudhart avatar Sep 12 '12 08:09 benrudhart

Also in the GM (4G182)

dickbrouwer avatar Sep 12 '12 23:09 dickbrouwer

Same problem

YuAo avatar Sep 18 '12 03:09 YuAo

Same here with the Release XCode 4.5 (4G182) Version!

carlj avatar Sep 20 '12 15:09 carlj

I tried adding NS_RETURNS_RETAINED to the function headers, the static analyzer still complains.

The two warnings are here:

  1. https://github.com/johnezang/JSONKit/blob/82157634ca0ca5b6a4a67a194dd11f15d9b72835/JSONKit.m#L682
  2. https://github.com/johnezang/JSONKit/blob/82157634ca0ca5b6a4a67a194dd11f15d9b72835/JSONKit.m#L933

shazron avatar Sep 21 '12 20:09 shazron

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.

GlennChiu avatar Sep 24 '12 23:09 GlennChiu

addition of those two lines crashed for me....

stokes770 avatar Sep 26 '12 20:09 stokes770

crashed for me too

catarino avatar Sep 28 '12 19:09 catarino

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

shazron avatar Sep 29 '12 03:09 shazron

I inspected https://github.com/shazron/JSONKit/commit/5c330695e8b689e6ffb5b79db23cb630b0e921f8 -- please see my comments there.

pianofab avatar Sep 29 '12 04:09 pianofab

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

GlennChiu avatar Sep 29 '12 21:09 GlennChiu

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).

Bo98 avatar Sep 30 '12 20:09 Bo98

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]

brado avatar Jan 22 '13 22:01 brado

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.

lkraider avatar Mar 21 '13 00:03 lkraider

+1

flather avatar Apr 23 '13 14:04 flather

+1

grzegorzkrukowski avatar May 27 '13 11:05 grzegorzkrukowski

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.

Bo98 avatar Jul 07 '13 13:07 Bo98

Really nice @Bo98 ! Thank you for the link.

dominik-hadl avatar Jul 23 '13 09:07 dominik-hadl

Has there been any traction on the dictionary create function? The fix at 2d97fd941bc6f3eac711c9c4256a830fd1fb9f25 for the JKDictionaryCreate doesn't seem to change anything

absessive avatar Aug 19 '13 19:08 absessive

Yeah, the dictionary create function is still moaning. I'll see if I can do anything about that.

Bo98 avatar Aug 19 '13 19:08 Bo98

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

absessive avatar Aug 20 '13 20:08 absessive