]> git.openfabrics.org - ~ardavis/dapl.git/commitdiff
Fix memory leak in error path
authorPatrick Marchand Latifi <patrick.latifi@qlogic.com>
Tue, 19 Feb 2008 11:17:29 +0000 (03:17 -0800)
committerArlin Davis <arlin.r.davis@intel.com>
Sat, 23 Feb 2008 00:21:09 +0000 (16:21 -0800)
Make sure we don't leak the hash table if dapl_hca_alloc fails.

Signed-off-by: Patrick Marchand Latifi <patrick.latifi@qlogic.com>
dapl/common/dapl_hca_util.c

index 9bf35da62a9f048045d5e1016333f86530b440a1..2b112b30be718c240c4038a52b9bff05dc6f7c51 100644 (file)
@@ -65,33 +65,46 @@ 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_os_memzero (hca_ptr, sizeof (DAPL_HCA));
+
+    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);
+    {
+       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;
 }
 
 /*