We pass reply_wake around without holding any locks. It might get
destructed by parallel timeouts of other replies that are faster than we
are. Make sure we hold a reference to avoid those races.
Signed-off-by: David Herrmann <dh.herrmann@gmail.com>
if (r->reply_dst == conn_dst &&
r->cookie == msg->cookie_reply) {
if (r->sync) {
- *reply_wake = r;
+ *reply_wake = kdbus_conn_reply_ref(r);
} else {
list_del_init(&r->entry);
kdbus_conn_reply_unref(r);
kdbus_conn_reply_sync(reply_wake, ret);
mutex_unlock(&conn_dst->lock);
+ kdbus_conn_reply_unref(reply_wake);
+
if (ret < 0)
goto exit_unref;
} else {