@@ -135,6 +135,22 @@ static void ld_rpc_send(struct plugin *plugin, struct json_stream *stream)
135
135
io_wake (plugin -> io_rpc_conn );
136
136
}
137
137
138
+
139
+ /* When cmd for request is gone, we use this as noop callback */
140
+ static struct command_result * ignore_cb (struct command * command ,
141
+ const char * buf ,
142
+ const jsmntok_t * result ,
143
+ void * arg )
144
+ {
145
+ return command_done ();
146
+ }
147
+
148
+ static void disable_request_cb (struct command * cmd , struct out_req * out )
149
+ {
150
+ out -> errcb = NULL ;
151
+ out -> cb = ignore_cb ;
152
+ }
153
+
138
154
/* FIXME: Move lightningd/jsonrpc to common/ ? */
139
155
140
156
struct out_req *
@@ -160,6 +176,10 @@ jsonrpc_request_start_(struct plugin *plugin, struct command *cmd,
160
176
out -> arg = arg ;
161
177
uintmap_add (& plugin -> out_reqs , out -> id , out );
162
178
179
+ /* If command goes away, don't call callbacks! */
180
+ if (out -> cmd )
181
+ tal_add_destructor2 (out -> cmd , disable_request_cb , out );
182
+
163
183
out -> js = new_json_stream (NULL , cmd , NULL );
164
184
json_object_start (out -> js , NULL );
165
185
json_add_string (out -> js , "jsonrpc" , "2.0" );
@@ -646,6 +666,10 @@ static void handle_rpc_reply(struct plugin *plugin, const jsmntok_t *toks)
646
666
json_tok_full_len (toks ),
647
667
json_tok_full (plugin -> rpc_buffer , toks ), id );
648
668
669
+ /* Remove destructor if one existed */
670
+ if (out -> cmd )
671
+ tal_del_destructor2 (out -> cmd , disable_request_cb , out );
672
+
649
673
/* We want to free this if callback doesn't. */
650
674
tal_steal (tmpctx , out );
651
675
uintmap_del (& plugin -> out_reqs , out -> id );
0 commit comments