From 8b8a4e5331ff448b076bc0355b48cbda5546e7f9 Mon Sep 17 00:00:00 2001 From: Kamal Heib Date: Thu, 2 Jan 2020 15:35:02 +0200 Subject: [PATCH] pyverbs: Raise exception right after create QP fails To avoid refcounting the QP when create_qp failed move the throw exception to be right after create QP. Signed-off-by: Kamal Heib --- pyverbs/qp.pyx | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/pyverbs/qp.pyx b/pyverbs/qp.pyx index 9d368b620..7622da1d7 100755 --- a/pyverbs/qp.pyx +++ b/pyverbs/qp.pyx @@ -891,6 +891,8 @@ cdef class QP(PyverbsCM): # let's infer the type. if issubclass(type(creator), Context): self._create_qp_ex(creator, init_attr) + if self.qp == NULL: + raise PyverbsRDMAErrno('Failed to create QP') ctx = creator self.context = ctx ctx.add_ref(self) @@ -902,14 +904,15 @@ cdef class QP(PyverbsCM): xrcd = init_attr.xrcd xrcd.add_ref(self) self.xrcd = xrcd + else: self._create_qp(creator, init_attr) + if self.qp == NULL: + raise PyverbsRDMAErrno('Failed to create QP') pd = creator self.pd = pd pd.add_ref(self) self.context = None - if self.qp == NULL: - raise PyverbsRDMAErrno('Failed to create QP') if qp_attr is not None: funcs = {e.IBV_QPT_RC: self.to_init, e.IBV_QPT_UC: self.to_init,