diff options
author | Jo-Philipp Wich <jo@mein.io> | 2020-10-19 23:49:58 +0200 |
---|---|---|
committer | Jo-Philipp Wich <jo@mein.io> | 2020-10-19 23:49:58 +0200 |
commit | 8acdbeb8e5ac3754173d811382a1e2da0ac7037d (patch) | |
tree | ecc2cb39bcc53addbb6246cf2d98720ea4e1b60e | |
parent | d25f725e54c64f90786b1449e89b6232429e2d6d (diff) |
lib: fix memory leaks in printf() and sprintf()
Signed-off-by: Jo-Philipp Wich <jo@mein.io>
-rw-r--r-- | lib.c | 8 |
1 files changed, 7 insertions, 1 deletions
@@ -1515,12 +1515,16 @@ next: static struct json_object * ut_sprintf(struct ut_state *s, uint32_t off, struct json_object *args) { + struct json_object *rv; char *str = NULL; size_t len; len = ut_printf_common(s, off, args, &str); + rv = xjs_new_string_len(str, len); - return xjs_new_string_len(str, len); + free(str); + + return rv; } static struct json_object * @@ -1532,6 +1536,8 @@ ut_printf(struct ut_state *s, uint32_t off, struct json_object *args) len = ut_printf_common(s, off, args, &str); len = fwrite(str, 1, len, stdout); + free(str); + return xjs_new_int64(len); } |