SIGSEGV bugs wsubus.impl.h when an origin access check fails
I fixed a couple of SIGSEGV bugs wsubus.impl.h when an origin access check fails (see below).
static inline void wsu_peer_deinit(struct lws *wsi, struct wsu_peer *peer)
{
if (peer->curr_msg.jtok) {
json_tokener_free(peer->curr_msg.jtok);
peer->curr_msg.jtok = NULL;
}
if (peer->write_q.next) {
// free everything from write queue
struct wsu_writereq *p, *n;
list_for_each_entry_safe(p, n, &peer->write_q, wq) {
lwsl_info("free write in progress %p\n", p);
list_del(&p->wq);
free(p);
}
}
if (peer->role == WSUBUS_ROLE_CLIENT) {
struct prog_context *prog = lws_context_user(lws_get_context(wsi));
// cancel each access check in progress
//
// NOTE:
// it is important that first we cancel access checks in progress
// (before cancelling calls in progress), since access check may
// reference a pending call in progress (namely a call to ubus session
// object)
if (peer->u.client.access_check_q.next) {
struct wsubus_client_access_check_ctx *p, *n;
list_for_each_entry_safe(p, n, &peer->u.client.access_check_q, acq) {
lwsl_info("free check in progress %p\n", p);
list_del(&p->acq);
wsubus_access_check__cancel(prog->ubus_ctx, p->req);
wsubus_access_check_free(p->req);
if (p->destructor)
p->destructor(p);
}
}
if (peer->u.client.rpc_call_q.next) {
struct list_head *p, *n;
// cancel all calls in progress
list_for_each_safe(p, n, &peer->u.client.rpc_call_q) {
list_del(p);
struct ws_request_base *base = container_of(p, struct ws_request_base, cq);
if (base->cancel_and_destroy) {
lwsl_debug("free req in progress %p\n", base);
base->cancel_and_destroy(base);
}
}
}
}
}