From a5afb4f811422195c427e77ce161a4355b5efaef Mon Sep 17 00:00:00 2001 From: Matt Morehouse Date: Fri, 7 Apr 2023 17:50:28 -0500 Subject: [PATCH] common: remove json_stream_log_suppress The function is tiny and was only used in one location. And that one location was leaking memory. Detected by ASan: ==2637667==ERROR: LeakSanitizer: detected memory leaks Direct leak of 7 byte(s) in 1 object(s) allocated from: #0 0x4cd758 in __interceptor_strdup #1 0x64c70c in json_stream_log_suppress_for_cmd lightning/lightningd/jsonrpc.c:597:31 #2 0x68a630 in json_getlog lightning/lightningd/log.c:974:2 ... SUMMARY: AddressSanitizer: 7 byte(s) leaked in 1 allocation(s). --- common/json_stream.c | 7 ------- common/json_stream.h | 3 --- lightningd/jsonrpc.c | 4 +++- 3 files changed, 3 insertions(+), 11 deletions(-) diff --git a/common/json_stream.c b/common/json_stream.c index 2a6c568a8..16fd5472c 100644 --- a/common/json_stream.c +++ b/common/json_stream.c @@ -95,13 +95,6 @@ static bool json_stream_still_writing(const struct json_stream *js) return js->writer != NULL; } -void json_stream_log_suppress(struct json_stream *js, const char *cmd_name) -{ - /* Really shouldn't be used for anything else */ - assert(streq(cmd_name, "getlog")); - js->log = NULL; -} - void json_stream_append(struct json_stream *js, const char *str, size_t len) { diff --git a/common/json_stream.h b/common/json_stream.h index 55a0e16a6..8420c530b 100644 --- a/common/json_stream.h +++ b/common/json_stream.h @@ -97,9 +97,6 @@ const char *json_stream_detach_filter(const tal_t *ctx, struct json_stream *js); */ void json_stream_close(struct json_stream *js, struct command *writer); -/* For low-level JSON stream access: */ -void json_stream_log_suppress(struct json_stream *js, const char *cmd_name); - /* '"fieldname" : [ ' or '[ ' if fieldname is NULL */ void json_array_start(struct json_stream *js, const char *fieldname); /* '"fieldname" : { ' or '{ ' if fieldname is NULL */ diff --git a/lightningd/jsonrpc.c b/lightningd/jsonrpc.c index 1d8635e1f..2a4d26ded 100644 --- a/lightningd/jsonrpc.c +++ b/lightningd/jsonrpc.c @@ -594,8 +594,10 @@ void json_stream_log_suppress_for_cmd(struct json_stream *js, const char *nm = cmd->json_cmd->name; const char *s = tal_fmt(tmpctx, "Suppressing logging of %s command", nm); log_io(cmd->jcon->log, LOG_IO_OUT, NULL, s, NULL, 0); - json_stream_log_suppress(js, strdup(nm)); + /* Really shouldn't be used for anything else */ + assert(streq(nm, "getlog")); + js->log = NULL; } static struct json_stream *json_start(struct command *cmd)