[PATCH 3/5] osm_port.c: osm_port_new fix memory leak

[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): [#def9]
opensm-3.3.20/opensm/osm_port.c:146: alloc_fn: Storage is returned from allocation function "malloc".
opensm-3.3.20/opensm/osm_port.c:146: var_assign: Assigning: "p_port" = storage returned from "malloc(168UL)".
opensm-3.3.20/opensm/osm_port.c:150: noescape: Resource "p_port" is not freed or pointed-to in "memset". [Note: The source code implementation of the function has been overridden by a builtin model.]
opensm-3.3.20/opensm/osm_port.c:151: noescape: Resource "&p_port->mcm_list" is not freed or pointed-to in "cl_qlist_init".
opensm-3.3.20/include/complib/cl_qlist.h:435:56: noescape: "cl_qlist_init(cl_qlist_t * const)" does not free or save its parameter "p_list".
opensm-3.3.20/opensm/osm_port.c:166: leaked_storage: Variable "p_port" going out of scope leaks the storage it points to.
|#  164|   	p_physp = osm_node_get_physp_ptr(p_parent_node, port_num);
|#  165|   	if (!p_physp)
|#  166|-> 		return NULL;
|#  167|
|#  168|   	CL_ASSERT(port_guid == osm_physp_get_port_guid(p_physp));

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

diff --git a/opensm/osm_port.c b/opensm/osm_port.c
index c732f990..1246edf9 100644
--- a/opensm/osm_port.c
+++ b/opensm/osm_port.c
@@ -162,8 +162,10 @@ osm_port_t *osm_port_new(IN const ib_node_info_t * p_ni,
 	   only the singular part that has this GUID is owned.
 	 */
 	p_physp = osm_node_get_physp_ptr(p_parent_node, port_num);
-	if (!p_physp)
+	if (!p_physp) {
+		free(p_port);
 		return NULL;
+	}
 
 	CL_ASSERT(port_guid == osm_physp_get_port_guid(p_physp));
 	p_port->p_physp = p_physp;
-- 
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