Skip to contentSkip to conversation

fetch: do not leak a refspec

PATCH In review Jim Meyering 2 participants 2 messages Jun 15, 2016

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 fetch: do not leak a refspec

---
Coverity spotted this.

 builtin/fetch.c |    6 ++++--
 1 files changed, 4 insertions(+), 2 deletions(-)
builtin/fetch.c +4 -2
index f9c41da..93c9938 100644
@@ -875,6 +875,7 @@ static int fetch_one(struct remote *remote, int argc, const char **argv)
 {
 	int i;
 	static const char **refs = NULL;
+	struct refspec *refspec;
 	int ref_nr = 0;
 	int exit_code;
 
@@ -915,8 +916,9 @@ static int fetch_one(struct remote *remote, int argc, const char **argv)
 
 	sigchain_push_common(unlock_pack_on_signal);
 	atexit(unlock_pack);
-	exit_code = do_fetch(transport,
-			parse_fetch_refspec(ref_nr, refs), ref_nr);
+	refspec = parse_fetch_refspec(ref_nr, refs);
+	exit_code = do_fetch(transport, refspec, ref_nr);
+	free(refspec);
 	transport_disconnect(transport);
 	transport = NULL;
 	return exit_code;

--
1.7.6.rc0.293.g40857

#1 lore raw
Quoted 3 lines · Jim Meyering

---
Coverity spotted this.

Thanks, will apply, but it seems that Coverity does not know or care that this codepath is used only once in the process and the process immediately exits after the small leak that we didn't bother spending two extra lines to plug, which is kind of sad.

Quoted 29 lines
 builtin/fetch.c |    6 ++++--
 1 files changed, 4 insertions(+), 2 deletions(-)
builtin/fetch.c +4 -3
index f9c41da..93c9938 100644
@@ -875,6 +875,7 @@ static int fetch_one(struct remote *remote, int argc, const char **argv)
 {
 	int i;
 	static const char **refs = NULL;
+	struct refspec *refspec;
 	int ref_nr = 0;
 	int exit_code;
 
@@ -915,8 +916,9 @@ static int fetch_one(struct remote *remote, int argc, const char **argv)
 
 	sigchain_push_common(unlock_pack_on_signal);
 	atexit(unlock_pack);
-	exit_code = do_fetch(transport,
-			parse_fetch_refspec(ref_nr, refs), ref_nr);
+	refspec = parse_fetch_refspec(ref_nr, refs);
+	exit_code = do_fetch(transport, refspec, ref_nr);
+	free(refspec);
 	transport_disconnect(transport);
 	transport = NULL;
 	return exit_code;
--

1.7.6.rc0.293.g40857