git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH 7/7] submodule: implement `module_clone` as a builtin helper

From
Jeff King <peff@peff.net>
Date
Aug 21, 2015, 14:22 UTC
Message-ID
<20150821142212.GA26130@sigill.intra.peff.net>
In-Reply-To
<1439857323-21048-8-git-send-email-sbeller@google.com>
On Mon, Aug 17, 2015 at 05:22:03PM -0700, Stefan Beller wrote:
Show 6 quoted lines
> +static int module_clone(int argc, const char **argv, const char *prefix)
> [...]
> +	/* Redirect the worktree of the submodule in the superprojects config */
> +	if (!is_absolute_path(sm_gitdir)) {
> +		char *s = (char*)sm_gitdir;
> +		strbuf_addf(&sb, "%s/%s", xgetcwd(), sm_gitdir);

Coverity noticed that this is a leak; xgetcwd actually returns a newly allocated buffer. I think you just want:

  if (strbuf_getcwd(&sb))
	die_errno("unable to get current working directory");
  strbuf_addf("/%s", sm_gitdir);
> +		sm_gitdir = strbuf_detach(&sb, NULL);
> +		strbuf_reset(&sb);

This reset is a noop after you've detached. It's not technically documented, but I do not think it is reasonable for it to work any other way. Maybe strbuf.h should make that promise.

> +	strbuf_addf(&sb, "%s/%s", xgetcwd(), path);
Ditto on the xgetcwd issue here.
-Peff
Previous: Stefan BellerNext: Stefan Beller
Message 18 of 19 in “Submodule improvements”
  1. 0/7 Submodule improvementsStefan Beller, Aug 18, 2015
  2. 1/7 submodule: implement a config API for lookup of .gitmodules valuesStefan Beller, Aug 18, 2015
  3. 2/7 submodule: extract functions for config set and lookupStefan Beller, Aug 18, 2015
  4. 3/7 submodule: use new config API for worktree configurationsStefan Beller, Aug 18, 2015
  5. 4/7 submodule: Allow errornous values for the fetchrecursesubmodules optionStefan Beller, Aug 18, 2015
  6. Junio C HamanoAug 19, 2015
  7. 5/7 submodule: implement `module_list` as a builtin helperStefan Beller, Aug 18, 2015
  8. Junio C HamanoAug 19, 2015
  9. Junio C HamanoAug 19, 2015
  10. Stefan BellerAug 19, 2015
  11. Stefan BellerAug 19, 2015
  12. 6/7 submodule: implement `module_name` as a builtin helperStefan Beller, Aug 18, 2015
  13. 7/7 submodule: implement `module_clone` as a builtin helperStefan Beller, Aug 18, 2015
  14. Stefan BellerAug 18, 2015
  15. 7/7 submodule: implement `module_clone` as a builtin helperStefan Beller, Aug 18, 2015
  16. Junio C HamanoAug 19, 2015
  17. Stefan BellerAug 19, 2015
  18. Jeff KingAug 21, 2015
  19. Stefan BellerAug 18, 2015

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.