Browse Source

jsonrpc: make lifetimes in error path clearer.

Saving one allocation isn't worth the confusion.

Reported-by: @ZmnSCPxj
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
ppa-0.6.1
Rusty Russell 7 years ago
committed by Christian Decker
parent
commit
fd04fca771
  1. 9
      lightningd/jsonrpc.c

9
lightningd/jsonrpc.c

@ -265,18 +265,19 @@ static void connection_complete_error(struct json_connection *jcon,
int code,
const struct json_result *data)
{
const tal_t *tmpctx = tal_tmpctx(jcon);
/* Use this to escape errmsg. */
struct json_result *errorres = new_json_result(jcon);
struct json_result *errorres = new_json_result(tmpctx);
const char *data_str;
json_add_string_escape(errorres, NULL, errmsg);
if (data)
data_str = tal_fmt(errorres, ", \"data\" : %s",
data_str = tal_fmt(tmpctx, ", \"data\" : %s",
json_result_string(data));
else
data_str = "";
json_done(jcon, take(tal_fmt(errorres,
json_done(jcon, take(tal_fmt(tmpctx,
"{ \"jsonrpc\": \"2.0\", "
" \"error\" : "
"{ \"code\" : %d,"
@ -286,7 +287,7 @@ static void connection_complete_error(struct json_connection *jcon,
json_result_string(errorres),
data_str,
id)));
tal_free(errorres);
tal_free(tmpctx);
}
struct json_result *null_response(const tal_t *ctx)

Loading…
Cancel
Save