From: Honggang Li <honli@xxxxxxxxxx> Issue was found by Coverity. To observer this resource leak, just input this command in the console: OpenSM $ dump_portguid file /tmp/c file /tmp/d . then: ls -l /proc/<opensm-pid>/fd You will find /tmp/c was not closed. Error: RESOURCE_LEAK (CWE-772): [#def5] opensm-3.3.20/opensm/osm_console.c:1682: alloc_fn: Storage is returned from allocation function "fopen". opensm-3.3.20/opensm/osm_console.c:1682: var_assign: Assigning: "output" = storage returned from "fopen(p_cmd, "w+")". opensm-3.3.20/opensm/osm_console.c:1682: overwrite_var: Overwriting "output" in "output = fopen(p_cmd, "w+")" leaks the storage that "output" points to. |# 1680| p_cmd = next_token(p_last); |# 1681| if (p_cmd) { |# 1682|-> output = fopen(p_cmd, "w+"); |# 1683| if (output == NULL) { |# 1684| fprintf(out, Signed-off-by: Honggang Li <honli@xxxxxxxxxx> --- opensm/osm_console.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/opensm/osm_console.c b/opensm/osm_console.c index 9b91a42a..641bdcd5 100644 --- a/opensm/osm_console.c +++ b/opensm/osm_console.c @@ -1679,6 +1679,8 @@ static void dump_portguid_parse(char **p_last, osm_opensm_t * p_osm, FILE * out) if (strcmp(p_cmd, "file") == 0) { p_cmd = next_token(p_last); if (p_cmd) { + if (output != out) + fclose(output); output = fopen(p_cmd, "w+"); if (output == NULL) { fprintf(out, -- 2.14.4