Message ID | 20220605235955.1296104-1-dominique.martinet@atmark-techno.com |
---|---|
State | Accepted |
Delegated to: | Stefano Babic |
Headers | show |
Series | parse_json: check json_object_put frees the object | expand |
> coverity detected that we always check json_object_put return value, so check > here as well. > In practice, wrong return value here means we've leaked some memory so output > a warning and continue. > Tested with a single-script json example > Signed-off-by: Dominique Martinet <dominique.martinet@atmark-techno.com> Applied to u-boot-imx, master, thanks ! Best regards, Stefano Babic
On 24.06.22 11:37, sbabic@denx.de wrote: >> coverity detected that we always check json_object_put return value, so check >> here as well. >> In practice, wrong return value here means we've leaked some memory so output >> a warning and continue. >> Tested with a single-script json example >> Signed-off-by: Dominique Martinet <dominique.martinet@atmark-techno.com> > Applied to u-boot-imx, master, thanks ! > ^------- Ok, I have to fix the script, of course it is not u-boot... Best regards, Stefano Babic
diff --git a/parser/parser.c b/parser/parser.c index 49c531d32c19..d720de22a78c 100644 --- a/parser/parser.c +++ b/parser/parser.c @@ -995,6 +995,9 @@ int parse_cfg (struct swupdate_cfg __attribute__ ((__unused__)) *swcfg, #endif #ifdef CONFIG_JSON + +#define JSON_OBJECT_FREED 1 + int parse_json(struct swupdate_cfg *swcfg, const char *filename) { int fd, ret; @@ -1048,7 +1051,9 @@ int parse_json(struct swupdate_cfg *swcfg, const char *filename) ret = parser(p, cfg, swcfg); - json_object_put(cfg); + if (json_object_put(cfg) != JSON_OBJECT_FREED) { + WARN("Leaking cfg json object"); + } free(string);
coverity detected that we always check json_object_put return value, so check here as well. In practice, wrong return value here means we've leaked some memory so output a warning and continue. Tested with a single-script json example Signed-off-by: Dominique Martinet <dominique.martinet@atmark-techno.com> --- parser/parser.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-)