diff mbox series

[3/5] osmtest.c: osmtest_parse_node delete p_node in error path

Message ID 20180828014834.3046-3-honli@redhat.com (mailing list archive)
State Not Applicable
Delegated to: Hal Rosenstock
Headers show
Series [1/5] osmt_service.c: fix resource leak in osmt_get_all_services_and_check_names | expand

Commit Message

Honggang LI Aug. 28, 2018, 1:48 a.m. UTC
From: Honggang Li <honli@redhat.com>

Issue was found by Coverity.

Error: RESOURCE_LEAK (CWE-772): [#def14]
opensm-3.3.20/osmtest/osmtest.c:6364: alloc_fn: Storage is returned from allocation function "node_new".
opensm-3.3.20/osmtest/include/osmtest_subnet.h:116:2: alloc_fn: Storage is returned from allocation function "malloc".
opensm-3.3.20/osmtest/include/osmtest_subnet.h:116:2: var_assign: Assigning: "p_obj" = "malloc(288UL)".
opensm-3.3.20/osmtest/include/osmtest_subnet.h:118:3: noescape: Resource "p_obj" is not freed or pointed-to in function "memset". [Note: The source code implementation of the function has been overridden by a builtin model.]
opensm-3.3.20/osmtest/include/osmtest_subnet.h:119:2: return_alloc: Returning allocated memory "p_obj".
opensm-3.3.20/osmtest/osmtest.c:6364: var_assign: Assigning: "p_node" = storage returned from "node_new()".
opensm-3.3.20/osmtest/osmtest.c:6572: leaked_storage: Variable "p_node" going out of scope leaks the storage it points to.
|# 6570|   Exit:
|# 6571|   	OSM_LOG_EXIT(&p_osmt->log);
|# 6572|-> 	return (status);
|# 6573|   }
|# 6574|

Comments

Hal Rosenstock Aug. 28, 2018, 10:47 a.m. UTC | #1
On 8/27/2018 9:48 PM, Honggang LI wrote:
> From: Honggang Li <honli@redhat.com>
> 
> Issue was found by Coverity.
> 
> Error: RESOURCE_LEAK (CWE-772): [#def14]
> opensm-3.3.20/osmtest/osmtest.c:6364: alloc_fn: Storage is returned from allocation function "node_new".
> opensm-3.3.20/osmtest/include/osmtest_subnet.h:116:2: alloc_fn: Storage is returned from allocation function "malloc".
> opensm-3.3.20/osmtest/include/osmtest_subnet.h:116:2: var_assign: Assigning: "p_obj" = "malloc(288UL)".
> opensm-3.3.20/osmtest/include/osmtest_subnet.h:118:3: noescape: Resource "p_obj" is not freed or pointed-to in function "memset". [Note: The source code implementation of the function has been overridden by a builtin model.]
> opensm-3.3.20/osmtest/include/osmtest_subnet.h:119:2: return_alloc: Returning allocated memory "p_obj".
> opensm-3.3.20/osmtest/osmtest.c:6364: var_assign: Assigning: "p_node" = storage returned from "node_new()".
> opensm-3.3.20/osmtest/osmtest.c:6572: leaked_storage: Variable "p_node" going out of scope leaks the storage it points to.
> |# 6570|   Exit:
> |# 6571|   	OSM_LOG_EXIT(&p_osmt->log);
> |# 6572|-> 	return (status);
> |# 6573|   }
> |# 6574|
> 
> ===========
> 
> Signed-off-by: Honggang Li <honli@redhat.com>

Thanks. Applied.

-- Hal
diff mbox series

Patch

===========

Signed-off-by: Honggang Li <honli@redhat.com>
---
 osmtest/osmtest.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/osmtest/osmtest.c b/osmtest/osmtest.c
index b7197bf3..812563c1 100644
--- a/osmtest/osmtest.c
+++ b/osmtest/osmtest.c
@@ -6374,6 +6374,7 @@  osmtest_parse_node(IN osmtest_t * const p_osmt,
 			OSM_LOG(&p_osmt->log, OSM_LOG_ERROR, "ERR 0119: "
 				"Unexpected end of file\n");
 			status = IB_ERROR;
+			node_delete(p_node);
 			goto Exit;
 		}