[PATCH 5/5] osm_ucast_nue.c: fix resource leak in nue_create_context

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



From: Honggang Li <honli@xxxxxxxxxx>

Issue was found by Coverity.

Error: RESOURCE_LEAK (CWE-772):
opensm-3.3.20/opensm/osm_ucast_nue.c:3159: alloc_fn: Storage is returned from allocation function "malloc".
opensm-3.3.20/opensm/osm_ucast_nue.c:3159: var_assign: Assigning: "nue_ctx" = storage returned from "malloc(336UL)".
opensm-3.3.20/opensm/osm_ucast_nue.c:3164: noescape: Resource "nue_ctx" is not freed or pointed-to in "create_context".
opensm-3.3.20/opensm/osm_ucast_nue.c:3109:43: noescape: "create_context(nue_context_t *)" does not free or save its parameter "nue_ctx".
opensm-3.3.20/opensm/osm_ucast_nue.c:3166: leaked_storage: Variable "nue_ctx" going out of scope leaks the storage it points to.
|# 3164|   		err = create_context(nue_ctx);
|# 3165|   		if (err)
|# 3166|-> 			return NULL;
|# 3167|   	} else {
|# 3168|   		OSM_LOG(osm->sm.ucast_mgr.p_log, OSM_LOG_ERROR,

Signed-off-by: Honggang Li <honli@xxxxxxxxxx>
---
 opensm/osm_ucast_nue.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/opensm/osm_ucast_nue.c b/opensm/osm_ucast_nue.c
index 13684738..0ef84ebc 100644
--- a/opensm/osm_ucast_nue.c
+++ b/opensm/osm_ucast_nue.c
@@ -3162,8 +3162,10 @@ static nue_context_t *nue_create_context(const osm_opensm_t * osm,
 		nue_ctx->routing_type = routing_type;
 		nue_ctx->mgr = (osm_ucast_mgr_t *) & (osm->sm.ucast_mgr);
 		err = create_context(nue_ctx);
-		if (err)
+		if (err) {
+			free(nue_ctx);
 			return NULL;
+		}
 	} else {
 		OSM_LOG(osm->sm.ucast_mgr.p_log, OSM_LOG_ERROR,
 			"ERR NUE01: cannot allocate memory for nue_ctx\n");
-- 
2.14.4




[Index of Archives]     [Linux USB Devel]     [Video for Linux]     [Linux Audio Users]     [Photo]     [Yosemite News]     [Yosemite Photos]     [Linux Kernel]     [Linux SCSI]     [XFree86]

  Powered by Linux