protect against closing cm_id inside the loop

Change-Id: I7fe9c5c48562a9e2b0364474759264f976c3c11e
Signed-off-by: Eyal Salomon <esalomon@mellanox.com>