From: Casey Bodley Date: Wed, 13 May 2015 17:15:10 +0000 (-0400) Subject: xio: fix for xio_msg release after teardown X-Git-Tag: v9.0.2~106^2~5 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=5c14a69395cc7faeedbc464af5c2e238788e171b;p=ceph.git xio: fix for xio_msg release after teardown The xio_msg pointers to be freed in XioPortal::release_xio_rsp() are no longer valid after a call to xio_connection_destroy(). We were already avoiding the call to xio_release_msg() in this case, but were still dereferencing the xio_msg for its user_context pointer. Moved the check for is_connected() outside of the loop to avoid any access to msg. Suggested-by: Vu Pham Signed-off-by: Casey Bodley --- diff --git a/src/msg/xio/XioPortal.h b/src/msg/xio/XioPortal.h index 090f451dfa81c..a32b2e299ca37 100644 --- a/src/msg/xio/XioPortal.h +++ b/src/msg/xio/XioPortal.h @@ -159,17 +159,16 @@ public: struct xio_msg *msg = xrsp->dequeue(); struct xio_msg *next_msg = NULL; int code; - while (msg) { + if (unlikely(!xrsp->xcon->conn || !xrsp->xcon->is_connected())) { + // NOTE: msg is not safe to dereference if the connection was torn down + xrsp->xcon->msg_release_fail(msg, ENOTCONN); + } + else while (msg) { next_msg = static_cast(msg->user_context); - if (unlikely(!xrsp->xcon->conn || !xrsp->xcon->is_connected())) - code = ENOTCONN; - else - code = xio_release_msg(msg); - if (unlikely(code)) { - /* very unlikely, so log it */ + code = xio_release_msg(msg); + if (unlikely(code)) /* very unlikely, so log it */ xrsp->xcon->msg_release_fail(msg, code); - } - msg = next_msg; + msg = next_msg; } xrsp->finalize(); /* unconditional finalize */ }