[ofa-general] Re: [PATCHv2] opensm/osm_perfmgr_db.c: Fix memory leak of db nodes

Sasha Khapyorsky sashak at voltaire.com
Mon Sep 21 07:35:53 PDT 2009


On 08:51 Mon 21 Sep     , Hal Rosenstock wrote:
> 
> Signed-off-by: Hal Rosenstock <hal.rosenstock at gmail.com>
> ---
> Changes since v1:
> Fix use after free issue
> 
> diff --git a/opensm/opensm/osm_perfmgr_db.c b/opensm/opensm/osm_perfmgr_db.c
> index e5dfc19..03f988d 100644
> --- a/opensm/opensm/osm_perfmgr_db.c
> +++ b/opensm/opensm/osm_perfmgr_db.c
> @@ -49,6 +49,8 @@
>  #include <opensm/osm_perfmgr.h>
>  #include <opensm/osm_opensm.h>
>  
> +static void free_node(db_node_t * node);
> +
>  /** =========================================================================
>   */
>  perfmgr_db_t *perfmgr_db_construct(osm_perfmgr_t *perfmgr)
> @@ -68,7 +70,17 @@ perfmgr_db_t *perfmgr_db_construct(osm_perfmgr_t *perfmgr)
>   */
>  void perfmgr_db_destroy(perfmgr_db_t * db)
>  {
> +	cl_map_item_t *item, *next_item;
> +	db_node_t *node;
> +
>  	if (db) {
> +		item = cl_qmap_head(&db->pc_data);
> +		while (item != cl_qmap_end(&db->pc_data)) {
> +			node = (db_node_t *)item;
> +			next_item = cl_qmap_next(item);
> +			free_node(node);
> +			item = next_item;
> +		}

And why do you need both 'item' and 'node' variables?

Sasha

>  		cl_plock_destroy(&db->lock);
>  		free(db);
>  	}
> 



More information about the general mailing list