mirror of
https://github.com/ElementsProject/lightning.git
synced 2024-11-20 02:27:51 +01:00
0b79538b18
This happened with the 800M JSON for the MCP listchannels on the raspberry pi, and tal calls abort() by default. We switch to raw malloc here; we could override the error hook for tal, but this is neater since we're doing low-level things anyway, I tested it manually with this patch: diff --git a/lightningd/json_stream.c b/lightningd/json_stream.c index cec9f5771..206ba37c0 100644 --- a/lightningd/json_stream.c +++ b/lightningd/json_stream.c @@ -43,6 +43,14 @@ static void free_json_stream_membuf(struct json_stream *js) free(membuf_cleanup(&js->outbuf)); } +static void *membuf_realloc_hack(struct membuf *mb, void *rawelems, + size_t newsize) +{ + if (newsize > 1000000000) + return NULL; + return realloc(rawelems, newsize); +} + struct json_stream *new_json_stream(const tal_t *ctx, struct command *writer, struct log *log) @@ -53,7 +61,7 @@ struct json_stream *new_json_stream(const tal_t *ctx, js->reader = NULL; /* We don't use tal here, because we handle failure externally (tal * helpfully aborts with a msg, which is usually right) */ - membuf_init(&js->outbuf, malloc(64), 64, membuf_realloc); + membuf_init(&js->outbuf, malloc(64), 64, membuf_realloc_hack); tal_add_destructor(js, free_json_stream_membuf); #if DEVELOPER js->wrapping = tal_arr(js, jsmntype_t, 0); Signed-off-by: Rusty Russell <rusty@rustcorp.com.au> |
||
---|---|---|
.. | ||
Makefile | ||
run-find_my_abspath.c | ||
run-invoice-select-inchan.c | ||
run-jsonrpc.c |