Message ID | 20180827064233.3218-3-honli@redhat.com (mailing list archive) |
---|---|
State | Not Applicable |
Delegated to: | Hal Rosenstock |
Headers | show |
Series | [1/5] Adjust BuildRequires for covscan | expand |
On 8/27/2018 2:42 AM, Honggang LI wrote: > From: Honggang Li <honli@redhat.com> > > 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@redhat.com> Thanks. Applied. -- Hal
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;