[PATCH 4/5] osmtest.c: osmtest_parse_port fix resource leak in error path

[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): [#def12]
opensm-3.3.20/osmtest/osmtest.c:6588: alloc_fn: Storage is returned from allocation function "port_new".
opensm-3.3.20/osmtest/include/osmtest_subnet.h:173:2: alloc_fn: Storage is returned from allocation function "malloc".
opensm-3.3.20/osmtest/include/osmtest_subnet.h:173:2: var_assign: Assigning: "p_obj" = "malloc(216UL)".
opensm-3.3.20/osmtest/include/osmtest_subnet.h:175: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:176:2: return_alloc: Returning allocated memory "p_obj".
opensm-3.3.20/osmtest/osmtest.c:6588: var_assign: Assigning: "p_port" = storage returned from "port_new()".
opensm-3.3.20/osmtest/osmtest.c:6977: leaked_storage: Variable "p_port" going out of scope leaks the storage it points to.
|# 6975|   Exit:
|# 6976|   	OSM_LOG_EXIT(&p_osmt->log);
|# 6977|-> 	return (status);
|# 6978|   }
|# 6979|

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

diff --git a/osmtest/osmtest.c b/osmtest/osmtest.c
index 812563c1..e6f91a81 100644
--- a/osmtest/osmtest.c
+++ b/osmtest/osmtest.c
@@ -6599,6 +6599,7 @@ osmtest_parse_port(IN osmtest_t * const p_osmt,
 			OSM_LOG(&p_osmt->log, OSM_LOG_ERROR, "ERR 0123: "
 				"Unexpected end of file\n");
 			status = IB_ERROR;
+			port_delete(p_port);
 			goto Exit;
 		}
 
-- 
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