Skip to content

Commit

Permalink
common: remove json_stream_log_suppress
Browse files Browse the repository at this point in the history
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).
  • Loading branch information
morehouse authored and cdecker committed Jun 5, 2023
1 parent c05d7e4 commit a5afb4f
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 11 deletions.
7 changes: 0 additions & 7 deletions common/json_stream.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down
3 changes: 0 additions & 3 deletions common/json_stream.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand Down
4 changes: 3 additions & 1 deletion lightningd/jsonrpc.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit a5afb4f

Please sign in to comment.