git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
From: Stefan Beller <sbeller@google.com>
To: git@vger.kernel.org, gitster@pobox.com
Cc: Stefan Beller <sbeller@google.com>,
	Jens.Lehmann@web.de, sunshine@sunshineco.com, j6t@kdbg.org
Subject: [PATCHv4 0/2] Port `git submodule init` from shell to C
Date: Wed, 27 Jan 2016 18:30:35 -0800	[thread overview]
Message-ID: <1453948237-9860-1-git-send-email-sbeller@google.com> (raw)
In-Reply-To: <xmqqtwm1e0ps.fsf@gitster.mtv.corp.google.com>

Hi,

I looked at this patch series again and fixed all memory leaks as found by
coverity scan.

This applies on top of sb/submodule-parallel-update

Thanks,
Stefan

Interdiff to v3:
diff --git a/builtin/submodule--helper.c b/builtin/submodule--helper.c
index c9b0c05..dd8b2a5 100644
--- a/builtin/submodule--helper.c
+++ b/builtin/submodule--helper.c
@@ -35,7 +35,7 @@ static char *get_default_remote(void)
 	if (git_config_get_string(sb.buf, &dest))
 		ret = xstrdup("origin");
 	else
-		ret = xstrdup(dest);
+		ret = dest;
 
 	strbuf_release(&sb);
 	return ret;
@@ -188,6 +188,7 @@ static int resolve_relative_url(int argc, const char **argv, const char *prefix)
 	res = relative_url(remoteurl, url, up_path);
 	puts(res);
 	free(res);
+	free(remoteurl);
 	return 0;
 }
 
@@ -209,6 +210,7 @@ static int resolve_relative_url_test(int argc, const char **argv, const char *pr
 	res = relative_url(remoteurl, url, up_path);
 	puts(res);
 	free(res);
+	free(remoteurl);
 	return 0;
 }
 
@@ -222,8 +224,9 @@ static void init_submodule(const char *path, const char *prefix, int quiet)
 	const struct submodule *sub;
 	struct strbuf sb = STRBUF_INIT;
 	char *url = NULL;
-	const char *upd = NULL;
-	const char *displaypath = relative_path(xgetcwd(), prefix, &sb);
+	char *upd = NULL;
+	char *cwd = xgetcwd();
+	const char *displaypath = relative_path(cwd, prefix, &sb);
 
 	/* Only loads from .gitmodules, no overlay with .git/config */
 	gitmodules_config();
@@ -261,6 +264,7 @@ static void init_submodule(const char *path, const char *prefix, int quiet)
 				remoteurl = xgetcwd();
 			url = relative_url(remoteurl, url, NULL);
 			strbuf_release(&remotesb);
+			free(remoteurl);
 		}
 
 		if (git_config_set(sb.buf, url))
@@ -269,26 +273,27 @@ static void init_submodule(const char *path, const char *prefix, int quiet)
 		if (!quiet)
 			printf(_("Submodule '%s' (%s) registered for path '%s'\n"),
 				sub->name, url, displaypath);
-		free(url);
 	}
 
 	/* Copy "update" setting when it is not set yet */
 	strbuf_reset(&sb);
 	strbuf_addf(&sb, "submodule.%s.update", sub->name);
-	if (git_config_get_string_const(sb.buf, &upd) && sub->update) {
-		upd = sub->update;
+	if (git_config_get_string(sb.buf, &upd) && sub->update) {
+		upd = xstrdup(sub->update);
 		if (strcmp(sub->update, "checkout") &&
 		    strcmp(sub->update, "rebase") &&
 		    strcmp(sub->update, "merge") &&
 		    strcmp(sub->update, "none")) {
 			fprintf(stderr, _("warning: unknown update mode '%s' suggested for submodule '%s'\n"),
 				upd, sub->name);
-			upd = "none";
+			upd = xstrdup("none");
 		}
 		if (git_config_set(sb.buf, upd))
 			die(_("Failed to register update mode for submodule path '%s'"), displaypath);
 	}
 	strbuf_release(&sb);
+	free(cwd);
+	free(upd);
+	free(url);
 }
 
 static int module_init(int argc, const char **argv, const char *prefix)


Stefan Beller (2):
  submodule: port resolve_relative_url from shell to C
  submodule: port init from shell to C

 builtin/submodule--helper.c | 326 +++++++++++++++++++++++++++++++++++++++++++-
 git-submodule.sh            | 118 +---------------
 t/t0060-path-utils.sh       |  42 ++++++
 3 files changed, 366 insertions(+), 120 deletions(-)

-- 
2.7.0.rc0.42.ge5f5e2d

  reply	other threads:[~2016-01-28  2:30 UTC|newest]

Thread overview: 26+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-01-15 23:37 [PATCH 0/2] Port `git submodule init` from shell to C Stefan Beller
2016-01-15 23:37 ` [PATCH 1/2] submodule: Port resolve_relative_url " Stefan Beller
2016-01-15 23:37 ` [PATCH 2/2] submodule: Port init " Stefan Beller
2016-01-19 23:17 ` [PATCH 0/2] Port `git submodule init` " Junio C Hamano
2016-01-20  2:03   ` [PATCHv2 " Stefan Beller
2016-01-20  2:03     ` [PATCHv2 1/2] submodule: port resolve_relative_url " Stefan Beller
2016-01-22 19:03       ` Johannes Sixt
2016-01-22 20:23         ` Stefan Beller
2016-01-20  2:03     ` [PATCHv2 2/2] submodule: port init " Stefan Beller
2016-01-20  3:24       ` [PATCHv3 " Stefan Beller
2016-01-20 21:01         ` Junio C Hamano
2016-01-20 22:33           ` Stefan Beller
2016-01-20 23:04             ` Junio C Hamano
2016-01-21 23:18         ` [PATCHv4 " Stefan Beller
2016-01-22 22:30           ` Junio C Hamano
2016-01-22 22:32             ` Stefan Beller
2016-01-22 23:32             ` [PATCHv3 0/2] Port `git submodule init` " Stefan Beller
2016-01-25 22:46               ` Junio C Hamano
2016-01-28  2:30                 ` Stefan Beller [this message]
2016-01-28  2:30                   ` [PATCHv4 1/2] submodule: port resolve_relative_url " Stefan Beller
2016-01-28 22:03                     ` Junio C Hamano
2016-01-28 22:11                       ` Stefan Beller
2016-01-28  2:30                   ` [PATCHv4 2/2] submodule: port init " Stefan Beller
2016-02-27  8:30                     ` Duy Nguyen
2016-01-22 23:32             ` [PATCHv3 1/2] submodule: port resolve_relative_url " Stefan Beller
2016-01-22 23:32             ` [PATCHv3 2/2] submodule: port init " Stefan Beller

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: http://vger.kernel.org/majordomo-info.html

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1453948237-9860-1-git-send-email-sbeller@google.com \
    --to=sbeller@google.com \
    --cc=Jens.Lehmann@web.de \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    --cc=j6t@kdbg.org \
    --cc=sunshine@sunshineco.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://80x24.org/mirrors/git.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).