Fix leaked json objects when there is a failure parsing
An example that was flagged from the app that uses libcper:
'''
Indirect leak of 96 byte(s) in 2 object(s) allocated from:
#0 0x7f93e0ddafdf in __interceptor_malloc ../../../../src/libsanitizer/asan/asan_malloc_linux.cpp:69
#1 0x7f93e0b97cde in json_object_new /json-c-json-c-0.17-20230812/json_object.c:321
#2 0x7f93e0b97cde in json_object_new_object /json-c-json-c-0.17-20230812/json_object.c:532
#3 0x7f93e0c8ac81 in cper_to_ir ../subprojects/libcper/cper-parse.c:45
'''
Change-Id: I6c77cf797bb369d6e459545cf021f31c47dbe6a0
Signed-off-by: Karthik Rajagopalan <krajagopalan@nvidia.com>
diff --git a/cper-parse.c b/cper-parse.c
index d0ddedb..4181a64 100644
--- a/cper-parse.c
+++ b/cper-parse.c
@@ -55,6 +55,10 @@
cper_file) != 1) {
printf("Invalid number of section headers: Header states %d sections, could not read section %d.\n",
header.SectionCount, i + 1);
+ // Free json objects
+ json_object_put(sections_ir);
+ json_object_put(section_descriptors_ir);
+ json_object_put(header_ir);
return NULL;
}
json_object_array_add(