]> git.openfabrics.org - ~ardavis/dapl.git/commitdiff
Make sure we don't leak the hash table if dapl_hca_alloc fails.
authorPatrick Marchand Latifi <patrick.latifi@qlogic.com>
Tue, 19 Feb 2008 11:19:37 +0000 (03:19 -0800)
committerArlin Davis <arlin.r.davis@intel.com>
Thu, 28 Feb 2008 00:13:37 +0000 (16:13 -0800)
Signed-off-by: Patrick Marchand Latifi <patrick.latifi@qlogic.com>
dapl/common/dapl_hca_util.c

index 2cfef0e72f4469c9d78a5547403f96451ce32846..f881a1e533f222872df84c4fdcf58b4aeb77c8af 100644 (file)
@@ -65,33 +65,45 @@ dapl_hca_alloc (
     DAPL_HCA   *hca_ptr;
 
     hca_ptr = dapl_os_alloc (sizeof (DAPL_HCA));
-    if ( NULL != hca_ptr )
+    if ( NULL == hca_ptr )
     {
-       dapl_os_memzero (hca_ptr, sizeof (DAPL_HCA));
+       goto bail;
+    }
 
-        if ( DAT_SUCCESS == dapls_hash_create (
-                 DAPL_HASH_TABLE_DEFAULT_CAPACITY, &hca_ptr->lmr_hash_table) )
-        {
-            dapl_os_lock_init(&hca_ptr->lock);
-            dapl_llist_init_head(&hca_ptr->ia_list_head);
+    dapl_os_memzero (hca_ptr, sizeof (DAPL_HCA));
+
+    if ( DAT_SUCCESS != dapls_hash_create (
+       DAPL_HASH_TABLE_DEFAULT_CAPACITY, &hca_ptr->lmr_hash_table) )
+    {
+       goto bail;
+    }
+
+    dapl_os_lock_init(&hca_ptr->lock);
+    dapl_llist_init_head(&hca_ptr->ia_list_head);
             
-            hca_ptr->name = dapl_os_strdup(name);
-            hca_ptr->ib_hca_handle = IB_INVALID_HANDLE;
-            hca_ptr->port_num = dapl_os_strtol(port, NULL, 0);
-           if (hca_ptr->name == NULL)
-           {
-               dapl_os_free (hca_ptr, sizeof (DAPL_HCA));
-               hca_ptr = NULL;
-           }
-        }
-        else
-        {
-            dapl_os_free (hca_ptr, sizeof (DAPL_HCA));
-            hca_ptr = NULL;
-        }
+    hca_ptr->name = dapl_os_strdup(name);
+    if ( NULL == hca_ptr->name )
+    {
+       goto bail;
     }
 
+    hca_ptr->ib_hca_handle = IB_INVALID_HANDLE;
+    hca_ptr->port_num = dapl_os_strtol(port, NULL, 0);
+
     return (hca_ptr);
+
+bail:
+    if ( NULL != hca_ptr )
+    {
+       if ( NULL != hca_ptr->lmr_hash_table )
+       {
+           dapls_hash_free (hca_ptr->lmr_hash_table);
+       }
+
+       dapl_os_free (hca_ptr, sizeof (DAPL_HCA));
+    }
+
+    return NULL;
 }
 
 /*