ctdb-ib: make sure the tevent_fd is removed before the fd is closed
authorStefan Metzmacher <metze@samba.org>
Fri, 5 Jun 2015 08:30:39 +0000 (10:30 +0200)
committerStefan Metzmacher <metze@samba.org>
Fri, 12 Jun 2015 15:08:18 +0000 (17:08 +0200)
BUG: https://bugzilla.samba.org/show_bug.cgi?id=11316

Signed-off-by: Stefan Metzmacher <metze@samba.org>
Reviewed-by: Volker Lendecke <vl@samba.org>
ctdb/ib/ibwrapper.c

index 3daab3e3c72b75a0833b13189203f785e366c325..51d39daeba35224200957014a507d6b5d44b84cf 100644 (file)
@@ -134,16 +134,16 @@ static int ibw_ctx_priv_destruct(struct ibw_ctx_priv *pctx)
 {
        DEBUG(DEBUG_DEBUG, ("ibw_ctx_priv_destruct(%p)\n", pctx));
 
+       /*
+        * tevent_fd must be removed before the fd is closed
+        */
+       TALLOC_FREE(pctx->cm_channel_event);
+
        /* destroy cm */
        if (pctx->cm_channel) {
                rdma_destroy_event_channel(pctx->cm_channel);
                pctx->cm_channel = NULL;
        }
-       if (pctx->cm_channel_event) {
-               /* TODO: do we have to do this here? */
-               talloc_free(pctx->cm_channel_event);
-               pctx->cm_channel_event = NULL;
-       }
        if (pctx->cm_id) {
                rdma_destroy_id(pctx->cm_id);
                pctx->cm_id = NULL;
@@ -166,6 +166,11 @@ static int ibw_conn_priv_destruct(struct ibw_conn_priv *pconn)
        /* pconn->wr_index is freed by talloc */
        /* pconn->wr_index[i] are freed by talloc */
 
+       /*
+        * tevent_fd must be removed before the fd is closed
+        */
+       TALLOC_FREE(pconn->verbs_channel_event);
+
        /* destroy verbs */
        if (pconn->cm_id!=NULL && pconn->cm_id->qp!=NULL) {
                rdma_destroy_qp(pconn->cm_id);
@@ -182,12 +187,6 @@ static int ibw_conn_priv_destruct(struct ibw_conn_priv *pconn)
                pconn->verbs_channel = NULL;
        }
 
-       /* must be freed here because its order is important */
-       if (pconn->verbs_channel_event) {
-               talloc_free(pconn->verbs_channel_event);
-               pconn->verbs_channel_event = NULL;
-       }
-
        /* free memory regions */
        ibw_free_mr(&pconn->buf_send, &pconn->mr_send);
        ibw_free_mr(&pconn->buf_recv, &pconn->mr_recv);