-
Bug
-
Resolution: Inactive
-
Minor
-
None
-
None
-
None
-
None
for example,
json_object *jresp = json_object_new_object(); if(condition) return;
here, we invoke json_object_new_object(), and then don't call any other json-c functions(such as below:
json_object_object_add(jresp, "adapter",
to transfer the owerships, then we should use json_object_put(jresp) to release the allocated memory.
To verify my opinion, I make some test as below:
$ cat json-test.c /* json-test.c */ #include <stdio.h> #include <stdio.h> #include <json-c/json.h> #include <mcheck.h> int main() { struct json_object* obj; mtrace(); obj = json_object_new_object(); return 0; } $ gcc -g -o json-test json-test.c -I/usr/include/json-c -L/usr/lib -ljson-c $ export MALLOC_TRACE=mtrace.out $ ./json-test $ mtrace json-test mtrace.out mtrace json mtrace.out Memory not freed: ----------------- Address Size Caller 0x000056264c4fe6a0 0x48 at 0x7f0e0ca33520 0x000056264c4fe6f0 0x58 at 0x7f0e0ca36f83 0x000056264c4fe750 0x200 at 0x7f0e0ca36fa5 $ cat json-test-new.c #include <stdio.h> #include <stdio.h> #include <json-c/json.h> #include <mcheck.h> int main() { struct json_object* obj; mtrace(); obj = json_object_new_object(); json_object_put(obj); return 0; } $ gcc -g -o json-test-new json-test-new.c -I/usr/include/json-c -L/usr/lib -ljson-c $ export MALLOC_TRACE=mtrace.out $ ./json-test-new $ mtrace json-test-new mtrace.out No memory leaks.
# | Subject | Branch | Project | Status | CR | V |
---|---|---|---|---|---|---|
25289,5 | Fix memory leak introduced by json_object_new_object() solo | master | apps/agl-service-helloworld | Status: MERGED | +2 | +1 |
25898,2 | Fix potential memory leak | master | apps/agl-service-unicens-controller | Status: MERGED | +2 | +1 |
25900,2 | Fix potential memory leak | master | apps/agl-service-network | Status: MERGED | +2 | +1 |
25922,1 | Fix potential memory leak | master | apps/agl-service-navigation | Status: MERGED | +2 | +1 |
25960,1 | Fix potential memory leak | master | apps/agl-service-signal-composer | Status: MERGED | +2 | +1 |
25978,1 | Fix potential memory leak | master | apps/agl-service-homescreen | Status: MERGED | +2 | +1 |
26057,1 | Fix potential memory leak | koi | apps/agl-service-homescreen | Status: MERGED | +2 | +1 |
26082,1 | Fix potential memory leak | master | apps/agl-service-geoclue | Status: MERGED | +2 | +1 |
26087,2 | Fix potential memory leak | master | apps/agl-service-bluetooth-map | Status: MERGED | +2 | +1 |
26109,1 | Fix potential memory leak | master | apps/agl-service-bluetooth | Status: MERGED | +2 | +1 |
26226,1 | Added AGL Test Framework documentation | master | AGL/documentation | Status: ABANDONED | 0 | 0 |
26331,2 | Fix potential memory leak | jellyfish | apps/agl-service-homescreen | Status: MERGED | +2 | +1 |