From 04f20c04c6e51ee061a44406b9a73bf54683d8eb Mon Sep 17 00:00:00 2001 From: Stefan Beller Date: Mon, 9 Mar 2015 09:58:22 -0700 Subject: connect.c: do not leak "conn" after showing diagnosis When git_connect() is called to see how the URL is parsed for debugging purposes with CONNECT_DIAG_URL set, the variable conn is leaked. At this point in the codeflow, it only has its memory and no other resource is associated with it, so it is sufficient to clean it up by just freeing it. Signed-off-by: Stefan Beller Signed-off-by: Junio C Hamano diff --git a/connect.c b/connect.c index ce0e121..6090211 100644 --- a/connect.c +++ b/connect.c @@ -739,6 +739,7 @@ struct child_process *git_connect(int fd[2], const char *url, free(hostandport); free(path); + free(conn); return NULL; } else { ssh = getenv("GIT_SSH_COMMAND"); -- cgit v0.10.2-6-g49f6 From c8a571d8bcef7f5687b5eb86654805c39f236e5d Mon Sep 17 00:00:00 2001 From: Stefan Beller Date: Tue, 10 Mar 2015 16:51:48 -0700 Subject: bundle.c: fix memory leak There was one continue statement without an accompanying `free(ref)`. Instead of adding that, replace all the free&&continue with a goto just after writing the refs, where we'd do the free anyway and then reloop. Signed-off-by: Stefan Beller Signed-off-by: Junio C Hamano diff --git a/bundle.c b/bundle.c index 2e2dbd5..f732c92 100644 --- a/bundle.c +++ b/bundle.c @@ -334,7 +334,7 @@ static int write_bundle_refs(int bundle_fd, struct rev_info *revs) if (e->item->flags & UNINTERESTING) continue; if (dwim_ref(e->name, strlen(e->name), sha1, &ref) != 1) - continue; + goto skip_write_ref; if (read_ref_full(e->name, RESOLVE_REF_READING, sha1, &flag)) flag = 0; display_ref = (flag & REF_ISSYMREF) ? e->name : ref; @@ -342,7 +342,7 @@ static int write_bundle_refs(int bundle_fd, struct rev_info *revs) if (e->item->type == OBJ_TAG && !is_tag_in_date_range(e->item, revs)) { e->item->flags |= UNINTERESTING; - continue; + goto skip_write_ref; } /* @@ -357,8 +357,7 @@ static int write_bundle_refs(int bundle_fd, struct rev_info *revs) if (!(e->item->flags & SHOWN) && e->item->type == OBJ_COMMIT) { warning(_("ref '%s' is excluded by the rev-list options"), e->name); - free(ref); - continue; + goto skip_write_ref; } /* * If you run "git bundle create bndl v1.0..v2.0", the @@ -388,8 +387,7 @@ static int write_bundle_refs(int bundle_fd, struct rev_info *revs) obj->flags |= SHOWN; add_pending_object(revs, obj, e->name); } - free(ref); - continue; + goto skip_write_ref; } ref_count++; @@ -397,6 +395,7 @@ static int write_bundle_refs(int bundle_fd, struct rev_info *revs) write_or_die(bundle_fd, " ", 1); write_or_die(bundle_fd, display_ref, strlen(display_ref)); write_or_die(bundle_fd, "\n", 1); + skip_write_ref: free(ref); } -- cgit v0.10.2-6-g49f6 From fd2014d42b3a4fb865d99e9a7943caa08082cada Mon Sep 17 00:00:00 2001 From: Stefan Beller Date: Mon, 9 Mar 2015 09:58:24 -0700 Subject: builtin/help.c: fix memory leak Signed-off-by: Stefan Beller Signed-off-by: Junio C Hamano diff --git a/builtin/help.c b/builtin/help.c index 6133fe4..a1f5a0a 100644 --- a/builtin/help.c +++ b/builtin/help.c @@ -456,7 +456,7 @@ static void list_common_guides_help(void) int cmd_help(int argc, const char **argv, const char *prefix) { int nongit; - const char *alias; + char *alias; enum help_format parsed_help_format; argc = parse_options(argc, argv, prefix, builtin_help_options, @@ -499,6 +499,7 @@ int cmd_help(int argc, const char **argv, const char *prefix) alias = alias_lookup(argv[0]); if (alias && !is_git_command(argv[0])) { printf_ln(_("`git %s' is aliased to `%s'"), argv[0], alias); + free(alias); return 0; } -- cgit v0.10.2-6-g49f6