Skip to contentSkip to conversation

opensm/osm_console.c: fix memory and file descriptor leaks

PATCH Superseded Yevgeny Kliteynik 3 participants 3 messages Sep 7, 2010 2 messages not in the archive InfiniBand

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 opensm/osm_console.c: fix memory and file descriptor leaks

---
 opensm/opensm/osm_console.c |    9 ++++++---
 1 files changed, 6 insertions(+), 3 deletions(-)
opensm/opensm/osm_console.c +6 -3
index bc7bea3..29a6c83 100644
@@ -1302,12 +1302,13 @@ static void dump_portguid_parse(char **p_last, osm_opensm_t * p_osm, FILE * out)
 	/* Check we have at least one expression to match */
 	if (p_head_regexp == NULL) {
 		fprintf(out, "No valid expression provided. Aborting\n");
+		goto Exit;
 		return;
 	}
 
 	if (p_osm->sm.p_subn->need_update != 0) {
 		fprintf(out, "Subnet is not ready yet. Try again later\n");
-		return;
+		goto Free_and_exit;
 	}
 
 	/* Subnet doesn't need to be updated so we can carry on */
@@ -1333,14 +1334,16 @@ static void dump_portguid_parse(char **p_last, osm_opensm_t * p_osm, FILE * out)
 	}
 
 	CL_PLOCK_RELEASE(p_osm->sm.p_lock);
-	if (output != out)
-		fclose(output);
 
+Free_and_exit:
 	for (; p_head_regexp; p_head_regexp = p_regexp) {
 		p_regexp = p_head_regexp->next;
 		regfree(&p_head_regexp->exp);
 		free(p_head_regexp);
 	}
+Exit:
+	if (output != out)
+		fclose(output);
 }
 
 static void help_dump_portguid(FILE * out, int detail)
Signature · 6 lines
1.6.2.4

--
To unsubscribe from this list: send the line "unsubscribe linux-rdma" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html

A message that is not in the archive (sent off-list or not yet received): 4C86567A.5060400-VPRAkNaXOzVS1MOuV/[email protected]

#2 lore raw

Hi Yevgeny,

Quoted 11 lines · On Tue, 7 Sep 2010 08:12:58 -0700 Yevgeny Kliteynik…
---
 opensm/opensm/osm_console.c |    9 ++++++---
 1 files changed, 6 insertions(+), 3 deletions(-)
opensm/opensm/osm_console.c +0 -0
index bc7bea3..29a6c83 100644

opensm/opensm/osm_console.c static void dump_portguid_parse(char **p_last, osm_opensm_t * p_osm, FILE * out) · line 1306

Quoted 5 lines
opensm/opensm/osm_console.c +1 -0
@@ -1302,12 +1302,13 @@ static void dump_portguid_parse(char **p_last, osm_opensm_t * p_osm, FILE * out)
 	/* Check we have at least one expression to match */
 	if (p_head_regexp == NULL) {
 		fprintf(out, "No valid expression provided. Aborting\n");
+		goto Exit;
 		return;

While you are at it, shouldn't you remove the return here as well?

Ira

Quoted 36 lines
opensm/opensm/osm_console.c +5 -3
 	}
 
 	if (p_osm->sm.p_subn->need_update != 0) {
 		fprintf(out, "Subnet is not ready yet. Try again later\n");
-		return;
+		goto Free_and_exit;
 	}
 
 	/* Subnet doesn't need to be updated so we can carry on */
@@ -1333,14 +1334,16 @@ static void dump_portguid_parse(char **p_last, osm_opensm_t * p_osm, FILE * out)
 	}
 
 	CL_PLOCK_RELEASE(p_osm->sm.p_lock);
-	if (output != out)
-		fclose(output);
 
+Free_and_exit:
 	for (; p_head_regexp; p_head_regexp = p_regexp) {
 		p_regexp = p_head_regexp->next;
 		regfree(&p_head_regexp->exp);
 		free(p_head_regexp);
 	}
+Exit:
+	if (output != out)
+		fclose(output);
 }
 
 static void help_dump_portguid(FILE * out, int detail)
Signature · 6 lines
1.6.2.4

--
To unsubscribe from this list: send the line "unsubscribe linux-rdma" in
the body of a message to [email protected]
More majordomo info at  http://*vger.kernel.org/majordomo-info.html
Signature · 9 lines
Ira Weiny
Math Programmer/Computer Scientist
Lawrence Livermore National Lab
925-423-8008
[email protected]
--
To unsubscribe from this list: send the line "unsubscribe linux-rdma" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html

A message that is not in the archive (sent off-list or not yet received): [email protected]

#4 lore raw
Quoted 11 lines · Ira Weiny

Hi Yevgeny,

Quoted 6 lines · On Tue, 7 Sep 2010 08:12:58 -0700 Yevgeny…
---
  opensm/opensm/osm_console.c |    9 ++++++---
  1 files changed, 6 insertions(+), 3 deletions(-)
Quoted 12 lines

opensm/opensm/osm_console.c static void dump_portguid_parse(char **p_last, osm_opensm_t * p_osm, FILE * out) · line 1306

Quoted 10 lines
opensm/opensm/osm_console.c +1 -0
index bc7bea3..29a6c83 100644
@@ -1302,12 +1302,13 @@ static void dump_portguid_parse(char **p_last, osm_opensm_t * p_osm, FILE * out)
  	/* Check we have at least one expression to match */
  	if (p_head_regexp == NULL) {
  		fprintf(out, "No valid expression provided. Aborting\n");
+		goto Exit;
  		return;

While you are at it, shouldn't you remove the return here as well?

Yep :)

-- Yevgeny

Quoted 33 lines

Ira

Quoted 31 lines
opensm/opensm/osm_console.c +5 -3
  	}
 
  	if (p_osm->sm.p_subn->need_update != 0) {
  		fprintf(out, "Subnet is not ready yet. Try again later\n");
-		return;
+		goto Free_and_exit;
  	}
 
  	/* Subnet doesn't need to be updated so we can carry on */
@@ -1333,14 +1334,16 @@ static void dump_portguid_parse(char **p_last, osm_opensm_t * p_osm, FILE * out)
  	}
 
  	CL_PLOCK_RELEASE(p_osm->sm.p_lock);
-	if (output != out)
-		fclose(output);
 
+Free_and_exit:
  	for (; p_head_regexp; p_head_regexp = p_regexp) {
  		p_regexp = p_head_regexp->next;
  		regfree(&p_head_regexp->exp);
  		free(p_head_regexp);
  	}
+Exit:
+	if (output != out)
+		fclose(output);
  }
 
  static void help_dump_portguid(FILE * out, int detail)
Signature · 1 line
1.6.2.4
Quoted 7 lines
Quoted 5 lines

--
To unsubscribe from this list: send the line "unsubscribe linux-rdma" in the body of a message to [email protected] More majordomo info at http://*vger.kernel.org/majordomo-info.html

--
To unsubscribe from this list: send the line "unsubscribe linux-rdma" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html