diff mbox series

[5/5] osmtest.c: osmtest_parse_path fix resource leak in error path

Message ID 20180828014834.3046-5-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): [#def13]
opensm-3.3.20/osmtest/osmtest.c:6994: alloc_fn: Storage is returned from allocation function "path_new".
opensm-3.3.20/osmtest/include/osmtest_subnet.h:254:2: alloc_fn: Storage is returned from allocation function "malloc".
opensm-3.3.20/osmtest/include/osmtest_subnet.h:254:2: var_assign: Assigning: "p_obj" = "malloc(192UL)".
opensm-3.3.20/osmtest/include/osmtest_subnet.h:256: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:257:2: return_alloc: Returning allocated memory "p_obj".
opensm-3.3.20/osmtest/osmtest.c:6994: var_assign: Assigning: "p_path" = storage returned from "path_new()".
opensm-3.3.20/osmtest/osmtest.c:7136: leaked_storage: Variable "p_path" going out of scope leaks the storage it points to.
|# 7134|   Exit:
|# 7135|   	OSM_LOG_EXIT(&p_osmt->log);
|# 7136|-> 	return (status);
|# 7137|   }
|# 7138|

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

Comments

Hal Rosenstock Aug. 28, 2018, 10:54 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): [#def13]
> opensm-3.3.20/osmtest/osmtest.c:6994: alloc_fn: Storage is returned from allocation function "path_new".
> opensm-3.3.20/osmtest/include/osmtest_subnet.h:254:2: alloc_fn: Storage is returned from allocation function "malloc".
> opensm-3.3.20/osmtest/include/osmtest_subnet.h:254:2: var_assign: Assigning: "p_obj" = "malloc(192UL)".
> opensm-3.3.20/osmtest/include/osmtest_subnet.h:256: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:257:2: return_alloc: Returning allocated memory "p_obj".
> opensm-3.3.20/osmtest/osmtest.c:6994: var_assign: Assigning: "p_path" = storage returned from "path_new()".
> opensm-3.3.20/osmtest/osmtest.c:7136: leaked_storage: Variable "p_path" going out of scope leaks the storage it points to.
> |# 7134|   Exit:
> |# 7135|   	OSM_LOG_EXIT(&p_osmt->log);
> |# 7136|-> 	return (status);
> |# 7137|   }
> |# 7138|
> 
> Signed-off-by: Honggang Li <honli@redhat.com>

Thanks. Applied.

-- Hal
diff mbox series

Patch

diff --git a/osmtest/osmtest.c b/osmtest/osmtest.c
index e6f91a81..8015bcec 100644
--- a/osmtest/osmtest.c
+++ b/osmtest/osmtest.c
@@ -7006,6 +7006,7 @@  osmtest_parse_path(IN osmtest_t * const p_osmt,
 			OSM_LOG(&p_osmt->log, OSM_LOG_ERROR, "ERR 0127: "
 				"Unexpected end of file\n");
 			status = IB_ERROR;
+			path_delete(p_path);
 			goto Exit;
 		}
 
@@ -7116,6 +7117,7 @@  osmtest_parse_path(IN osmtest_t * const p_osmt,
 
 	if (got_error) {
 		status = IB_ERROR;
+		path_delete(p_path);
 		goto Exit;
 	}
 	/*