[ofa-general] [PATCH] librdmacm: Add NULL pointer check in ucma_cleanup

Anoop acv at linux.vnet.ibm.com
Sun Aug 31 03:32:02 PDT 2008


If ibv_open_device failed, Segfault will occur at
libibverbs-1.1.1/src/device.c, since context is NULL
int __ibv_close_device(struct ibv_context *context)
{
        int async_fd = context->async_fd; <======
        int cmd_fd   = context->cmd_fd;
        int cq_fd    = -1;

The check is missing at librdmacm-1.0.7/src/cma.c
static void ucma_cleanup(void)
{
  if (cma_dev_cnt) {
    while (cma_dev_cnt)
      ibv_close_device(cma_dev_array[--cma_dev_cnt].verbs); <======

Signed-off-by: Anoop Vijayan <acv at linux.vnet.ibm.com>

--- librdmacm-1.0.7/src/cma.c.orig  2008-08-31 05:18:49.000000000 -0400
+++ librdmacm-1.0.7/src/cma.c   2008-08-31 05:20:37.000000000 -0400
@@ -163,9 +163,11 @@ static int abi_ver = RDMA_USER_CM_MAX_AB
 static void ucma_cleanup(void)
 {
    if (cma_dev_cnt) {
-       while (cma_dev_cnt)
-           ibv_close_device(cma_dev_array[--cma_dev_cnt].verbs);
-
+       while (cma_dev_cnt) {
+           if (cma_dev_array[--cma_dev_cnt].verbs)
+               ibv_close_device(cma_dev_array[cma_dev_cnt].verbs);
+       }
+
        free(cma_dev_array);
        cma_dev_cnt = 0;
    }


Cheers!
- Anoop.



More information about the general mailing list