summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorJo-Philipp Wich <jo@mein.io>2020-10-19 23:49:58 +0200
committerJo-Philipp Wich <jo@mein.io>2020-10-19 23:49:58 +0200
commit8acdbeb8e5ac3754173d811382a1e2da0ac7037d (patch)
treeecc2cb39bcc53addbb6246cf2d98720ea4e1b60e
parentd25f725e54c64f90786b1449e89b6232429e2d6d (diff)
lib: fix memory leaks in printf() and sprintf()
Signed-off-by: Jo-Philipp Wich <jo@mein.io>
-rw-r--r--lib.c8
1 files changed, 7 insertions, 1 deletions
diff --git a/lib.c b/lib.c
index 2de6921..809fef0 100644
--- a/lib.c
+++ b/lib.c
@@ -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);
}