mirror of
https://github.com/aljazceru/lightning.git
synced 2025-12-19 15:14:23 +01:00
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>
This commit is contained in:
committed by
Christian Decker
parent
dec86e0115
commit
fd04fca771
@@ -265,18 +265,19 @@ static void connection_complete_error(struct json_connection *jcon,
|
|||||||
int code,
|
int code,
|
||||||
const struct json_result *data)
|
const struct json_result *data)
|
||||||
{
|
{
|
||||||
|
const tal_t *tmpctx = tal_tmpctx(jcon);
|
||||||
/* Use this to escape errmsg. */
|
/* 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;
|
const char *data_str;
|
||||||
|
|
||||||
json_add_string_escape(errorres, NULL, errmsg);
|
json_add_string_escape(errorres, NULL, errmsg);
|
||||||
if (data)
|
if (data)
|
||||||
data_str = tal_fmt(errorres, ", \"data\" : %s",
|
data_str = tal_fmt(tmpctx, ", \"data\" : %s",
|
||||||
json_result_string(data));
|
json_result_string(data));
|
||||||
else
|
else
|
||||||
data_str = "";
|
data_str = "";
|
||||||
|
|
||||||
json_done(jcon, take(tal_fmt(errorres,
|
json_done(jcon, take(tal_fmt(tmpctx,
|
||||||
"{ \"jsonrpc\": \"2.0\", "
|
"{ \"jsonrpc\": \"2.0\", "
|
||||||
" \"error\" : "
|
" \"error\" : "
|
||||||
"{ \"code\" : %d,"
|
"{ \"code\" : %d,"
|
||||||
@@ -286,7 +287,7 @@ static void connection_complete_error(struct json_connection *jcon,
|
|||||||
json_result_string(errorres),
|
json_result_string(errorres),
|
||||||
data_str,
|
data_str,
|
||||||
id)));
|
id)));
|
||||||
tal_free(errorres);
|
tal_free(tmpctx);
|
||||||
}
|
}
|
||||||
|
|
||||||
struct json_result *null_response(const tal_t *ctx)
|
struct json_result *null_response(const tal_t *ctx)
|
||||||
|
|||||||
Reference in New Issue
Block a user