Skip to content

Commit cae1d82

Browse files
morehouserustyrussell
authored andcommitted
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).
1 parent a39db42 commit cae1d82

File tree

3 files changed

+3
-11
lines changed

3 files changed

+3
-11
lines changed

common/json_stream.c

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -95,13 +95,6 @@ static bool json_stream_still_writing(const struct json_stream *js)
9595
return js->writer != NULL;
9696
}
9797

98-
void json_stream_log_suppress(struct json_stream *js, const char *cmd_name)
99-
{
100-
/* Really shouldn't be used for anything else */
101-
assert(streq(cmd_name, "getlog"));
102-
js->log = NULL;
103-
}
104-
10598
void json_stream_append(struct json_stream *js,
10699
const char *str, size_t len)
107100
{

common/json_stream.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -97,9 +97,6 @@ const char *json_stream_detach_filter(const tal_t *ctx, struct json_stream *js);
9797
*/
9898
void json_stream_close(struct json_stream *js, struct command *writer);
9999

100-
/* For low-level JSON stream access: */
101-
void json_stream_log_suppress(struct json_stream *js, const char *cmd_name);
102-
103100
/* '"fieldname" : [ ' or '[ ' if fieldname is NULL */
104101
void json_array_start(struct json_stream *js, const char *fieldname);
105102
/* '"fieldname" : { ' or '{ ' if fieldname is NULL */

lightningd/jsonrpc.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -594,8 +594,10 @@ void json_stream_log_suppress_for_cmd(struct json_stream *js,
594594
const char *nm = cmd->json_cmd->name;
595595
const char *s = tal_fmt(tmpctx, "Suppressing logging of %s command", nm);
596596
log_io(cmd->jcon->log, LOG_IO_OUT, NULL, s, NULL, 0);
597-
json_stream_log_suppress(js, strdup(nm));
598597

598+
/* Really shouldn't be used for anything else */
599+
assert(streq(nm, "getlog"));
600+
js->log = NULL;
599601
}
600602

601603
static struct json_stream *json_start(struct command *cmd)

0 commit comments

Comments
 (0)