[ofa-general] [PATCH 2/3] osm: QoS - fixing memory leaks

Yevgeny Kliteynik kliteyn at dev.mellanox.co.il
Tue Oct 9 02:00:38 PDT 2007


Fixing bunch of memory leaks and pointer mismatches in QoS.

Signed-off-by: Yevgeny Kliteynik <kliteyn at dev.mellanox.co.il>
---
 opensm/opensm/osm_qos_parser.l |   16 ++++++++++++----
 opensm/opensm/osm_qos_parser.y |   15 ++++++++-------
 opensm/opensm/osm_qos_policy.c |   21 +++++++++++++--------
 3 files changed, 33 insertions(+), 19 deletions(-)

diff --git a/opensm/opensm/osm_qos_parser.l b/opensm/opensm/osm_qos_parser.l
index 0b096f8..60b2d1c 100644
--- a/opensm/opensm/osm_qos_parser.l
+++ b/opensm/opensm/osm_qos_parser.l
@@ -260,33 +260,41 @@ WHITE_DOTDOT_WHITE      [ \t]*:[ \t]*

 -                   {
                         SAVE_POS;
-                        __qos_parser_lval = strdup(__qos_parser_text);
                         if (in_description || in_list_of_strings || in_single_string)
+                        {
+                            __qos_parser_lval = strdup(__qos_parser_text);
                             return TK_TEXT;
+                        }
                         return TK_DASH;
                     }

 :                   {
                         SAVE_POS;
-                        __qos_parser_lval = strdup(__qos_parser_text);
                         if (in_description || in_list_of_strings || in_single_string)
+                        {
+                            __qos_parser_lval = strdup(__qos_parser_text);
                             return TK_TEXT;
+                        }
                         return TK_DOTDOT;
                     }

 ,                   {
                         SAVE_POS;
-                        __qos_parser_lval = strdup(__qos_parser_text);
                         if (in_description)
+                        {
+                            __qos_parser_lval = strdup(__qos_parser_text);
                             return TK_TEXT;
+                        }
                         return TK_COMMA;
                     }

 \*                  {
                         SAVE_POS;
-                        __qos_parser_lval = strdup(__qos_parser_text);
                         if (in_description || in_list_of_strings || in_single_string)
+                        {
+                            __qos_parser_lval = strdup(__qos_parser_text);
                             return TK_TEXT;
+                        }
                         return TK_ASTERISK;
                     }

diff --git a/opensm/opensm/osm_qos_parser.y b/opensm/opensm/osm_qos_parser.y
index 8e9f282..2405519 100644
--- a/opensm/opensm/osm_qos_parser.y
+++ b/opensm/opensm/osm_qos_parser.y
@@ -2105,15 +2105,15 @@ static void __sort_reduce_rangearr(
     unsigned last_valid_ind = 0;
     unsigned valid_cnt = 0;
     uint64_t ** res_arr;
-    boolean_t * is_valir_arr;
+    boolean_t * is_valid_arr;

     *p_res_arr = NULL;
     *p_res_arr_len = 0;

     qsort(arr, arr_len, sizeof(uint64_t*), __cmp_num_range);

-    is_valir_arr = (boolean_t *)malloc(arr_len * sizeof(boolean_t));
-    is_valir_arr[last_valid_ind] = TRUE;
+    is_valid_arr = (boolean_t *)malloc(arr_len * sizeof(boolean_t));
+    is_valid_arr[last_valid_ind] = TRUE;
     valid_cnt++;
     for (i = 1; i < arr_len; i++)
     {
@@ -2123,18 +2123,18 @@ static void __sort_reduce_rangearr(
                 arr[last_valid_ind][1] = arr[i][1];
             free(arr[i]);
             arr[i] = NULL;
-            is_valir_arr[i] = FALSE;
+            is_valid_arr[i] = FALSE;
         }
         else if ((arr[i][0] - 1) == arr[last_valid_ind][1])
         {
             arr[last_valid_ind][1] = arr[i][1];
             free(arr[i]);
             arr[i] = NULL;
-            is_valir_arr[i] = FALSE;
+            is_valid_arr[i] = FALSE;
         }
         else
         {
-            is_valir_arr[i] = TRUE;
+            is_valid_arr[i] = TRUE;
             last_valid_ind = i;
             valid_cnt++;
         }
@@ -2143,9 +2143,10 @@ static void __sort_reduce_rangearr(
     res_arr = (uint64_t **)malloc(valid_cnt * sizeof(uint64_t *));
     for (i = 0; i < arr_len; i++)
     {
-        if (is_valir_arr[i])
+        if (is_valid_arr[i])
             res_arr[j++] = arr[i];
     }
+    free(is_valid_arr);
     free(arr);

     *p_res_arr = res_arr;
diff --git a/opensm/opensm/osm_qos_policy.c b/opensm/opensm/osm_qos_policy.c
index c84fb8b..51dd7b9 100644
--- a/opensm/opensm/osm_qos_policy.c
+++ b/opensm/opensm/osm_qos_policy.c
@@ -101,12 +101,6 @@ static void __free_single_element(void *p_element, void *context)
 		free(p_element);
 }

-static void __free_port_map_element(cl_map_item_t *p_element, void *context)
-{
-	if (p_element)
-		free(p_element);
-}
-
 /***************************************************
  ***************************************************/

@@ -145,6 +139,9 @@ osm_qos_port_group_t *osm_qos_policy_port_group_create()

 void osm_qos_policy_port_group_destroy(osm_qos_port_group_t * p)
 {
+	osm_qos_port_t * p_port;
+	osm_qos_port_t * p_old_port;
+
 	if (!p)
 		return;

@@ -157,7 +154,13 @@ void osm_qos_policy_port_group_destroy(osm_qos_port_group_t * p)
 	cl_list_remove_all(&p->port_name_list);
 	cl_list_destroy(&p->port_name_list);

-	cl_qmap_apply_func(&p->port_map,  __free_port_map_element,  NULL);
+	p_port = (osm_qos_port_t *) cl_qmap_head(&p->port_map);
+	while (p_port != (osm_qos_port_t *) cl_qmap_end(&p->port_map))
+	{
+		p_old_port = p_port;
+		p_port = (osm_qos_port_t *) cl_qmap_next(&p_port->map_item);
+		free(p_old_port);
+	}
 	cl_qmap_remove_all(&p->port_map);

 	free(p);
@@ -219,7 +222,7 @@ osm_qos_sl2vl_scope_t *osm_qos_policy_sl2vl_scope_create()
 	if (!p)
 		return NULL;

-	memset(p, 0, sizeof(osm_qos_vlarb_scope_t));
+	memset(p, 0, sizeof(osm_qos_sl2vl_scope_t));

 	cl_list_init(&p->group_list, 10);
 	cl_list_init(&p->across_from_list, 10);
@@ -274,6 +277,8 @@ void osm_qos_policy_qos_level_destroy(osm_qos_level_t * p)
 	if (!p)
 		return;

+	if (p->name)
+		free(p->name);
 	if (p->use)
 		free(p->use);

-- 
1.5.1.4





More information about the general mailing list