[openib-general] [PATCH][MINOR] OpenSM/osm_ucast_updn.c: Handle more malloc failures better

Hal Rosenstock halr at voltaire.com
Mon Jan 15 20:42:14 PST 2007


OpenSM/osm_ucast_updn.c: Handle more malloc failures better

Signed-off-by: Hal Rosenstock <halr at voltaire.com>

diff --git a/osm/opensm/osm_ucast_updn.c b/osm/opensm/osm_ucast_updn.c
index 4450b6b..59d5daa 100644
--- a/osm/opensm/osm_ucast_updn.c
+++ b/osm/opensm/osm_ucast_updn.c
@@ -242,6 +242,15 @@ __updn_bfs_by_node(
 
   /* Init the list pointers */
   p_nextList = (cl_list_t*)malloc(sizeof(cl_list_t));
+  if (!p_nextList)
+  {
+    osm_log( p_log, OSM_LOG_ERROR,
+             "__updn_bfs_by_node: ERR AA14: "
+             "No memory for p_nextList\n" );
+    OSM_LOG_EXIT( p_log );
+    return 1;
+  }
+
   cl_list_construct( p_nextList );
   cl_list_init( p_nextList, 10 );
   p_currList = p_nextList;
@@ -354,6 +363,15 @@ __updn_bfs_by_node(
              cl_list_count(p_currList) );
     /* Init the switch directed list */
     p_nextList = (cl_list_t*)malloc(sizeof(cl_list_t));
+    if (!p_nextList)
+    {
+      osm_log( p_log, OSM_LOG_ERROR,
+               "__updn_bfs_by_node: ERR AA15: "
+               "No memory for p_nextList\n" );
+      OSM_LOG_EXIT( p_log );
+      return 1;
+    }
+
     cl_list_construct( p_nextList );
     cl_list_init( p_nextList, 10 );
     /* Go over all current list items till it's empty */
@@ -705,6 +723,15 @@ updn_subn_rank(
 
   /* Init the list pointers */
   p_nextList = (cl_list_t*)malloc(sizeof(cl_list_t));
+  if (!p_nextList)
+  {
+    osm_log( p_log, OSM_LOG_ERROR,
+             "updn_subn_rank: ERR AA15: "
+             "No memory for p_nextList\n" );
+    OSM_LOG_EXIT( p_log );
+    return 1;
+  }
+
   cl_list_construct( p_nextList );
   cl_list_init( p_nextList, 10 );
   p_currList = p_nextList;
@@ -759,6 +786,15 @@ updn_subn_rank(
   {
     rank++;
     p_nextList = (cl_list_t*)malloc(sizeof(cl_list_t));
+    if (!p_nextList)
+    {
+      osm_log( p_log, OSM_LOG_ERROR,
+               "updn_subn_rank: ERR AA16: "
+               "No memory for p_nextList\n" );
+      OSM_LOG_EXIT( p_log );
+      return 1;
+    }
+
     cl_list_construct( p_nextList );
     cl_list_init( p_nextList, 10 );
     p_physp = (osm_physp_t*)cl_list_remove_head( p_currList );
@@ -1238,12 +1274,21 @@ __osm_updn_find_root_nodes_by_min_hop(
     if ( (numHopBarsOverThd1 == 1) && (numHopBarsOverThd2 == 1) )
     {
       p_guid = malloc(sizeof(uint64_t));
-      *p_guid = cl_ntoh64(osm_node_get_node_guid(p_sw->p_node));
-      osm_log( &p_osm->log, OSM_LOG_DEBUG,
-               "__osm_updn_find_root_nodes_by_min_hop: "
-               "Inserting GUID 0x%" PRIx64 " as root node\n",
-               *p_guid );
-      cl_list_insert_tail(p_root_nodes_list, p_guid);
+      if (p_guid)
+      {
+        *p_guid = cl_ntoh64(osm_node_get_node_guid(p_sw->p_node));
+        osm_log( &p_osm->log, OSM_LOG_DEBUG,
+                 "__osm_updn_find_root_nodes_by_min_hop: "
+                 "Inserting GUID 0x%" PRIx64 " as root node\n",
+                 *p_guid );
+        cl_list_insert_tail(p_root_nodes_list, p_guid);
+      }
+      else
+      {
+        osm_log( &p_osm->log, OSM_LOG_ERROR,
+                 "__osm_updn_find_root_nodes_by_min_hop: ERR AA13: "
+                 "No memory for p_guid\n" );
+      }
     }
   }
 







More information about the general mailing list