mirror of
https://github.com/ElementsProject/lightning.git
synced 2025-02-22 06:41:44 +01:00
lightningd: don't leave htlc_out's in pointer dangling when htlc_in freed.
Now we know this can happen (see previous patch), we need to handle it. Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
This commit is contained in:
parent
4040c53258
commit
9ef67e50ff
3 changed files with 28 additions and 2 deletions
|
@ -213,6 +213,27 @@ struct htlc_out *htlc_out_check(const struct htlc_out *hout,
|
|||
return cast_const(struct htlc_out *, hout);
|
||||
}
|
||||
|
||||
static void htlc_out_clear_hin(struct htlc_in *hin, struct htlc_out *hout)
|
||||
{
|
||||
assert(hout->in == hin);
|
||||
hout->in = NULL;
|
||||
}
|
||||
|
||||
static void destroy_htlc_out_with_hin(struct htlc_out *hout)
|
||||
{
|
||||
/* Don't try to clear our ptr if we're freed before hin! */
|
||||
if (hout->in)
|
||||
tal_del_destructor2(hout->in, htlc_out_clear_hin, hout);
|
||||
}
|
||||
|
||||
void htlc_out_connect_htlc_in(struct htlc_out *hout, struct htlc_in *hin)
|
||||
{
|
||||
assert(!hout->in);
|
||||
hout->in = hin;
|
||||
tal_add_destructor2(hin, htlc_out_clear_hin, hout);
|
||||
tal_add_destructor(hout, destroy_htlc_out_with_hin);
|
||||
}
|
||||
|
||||
/* You need to set the ID, then connect_htlc_out this! */
|
||||
struct htlc_out *new_htlc_out(const tal_t *ctx,
|
||||
struct channel *channel,
|
||||
|
@ -241,7 +262,9 @@ struct htlc_out *new_htlc_out(const tal_t *ctx,
|
|||
hout->preimage = NULL;
|
||||
|
||||
hout->local = local;
|
||||
hout->in = in;
|
||||
hout->in = NULL;
|
||||
if (in)
|
||||
htlc_out_connect_htlc_in(hout, in);
|
||||
|
||||
return htlc_out_check(hout, "new_htlc_out");
|
||||
}
|
||||
|
|
|
@ -138,6 +138,9 @@ struct htlc_out *new_htlc_out(const tal_t *ctx,
|
|||
void connect_htlc_in(struct htlc_in_map *map, struct htlc_in *hin);
|
||||
void connect_htlc_out(struct htlc_out_map *map, struct htlc_out *hout);
|
||||
|
||||
/* Set up hout->in to be hin (non-NULL), and clear if hin freed. */
|
||||
void htlc_out_connect_htlc_in(struct htlc_out *hout, struct htlc_in *hin);
|
||||
|
||||
struct htlc_out *htlc_out_check(const struct htlc_out *hout,
|
||||
const char *abortstr);
|
||||
struct htlc_in *htlc_in_check(const struct htlc_in *hin, const char *abortstr);
|
||||
|
|
|
@ -1712,7 +1712,7 @@ void htlcs_reconnect(struct lightningd *ld,
|
|||
"Found corresponding htlc_in %" PRIu64
|
||||
" for htlc_out %" PRIu64,
|
||||
hin->dbid, hout->dbid);
|
||||
hout->in = hin;
|
||||
htlc_out_connect_htlc_in(hout, hin);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue