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

[PATCH v3 3/5] builtin/mv.c: plug miniscule memory leak

From
Brandon Casey <casey@nrlssc.navy.mil>
Date
Oct 6, 2011, 18:22 UTC
Message-ID
<U4wiHVyDLLG1PhI-8iY3YqpVXvr151LbD3OSy1NeXQm5ByYpuasT4PQ2mikx8l9NCM-x0SQVCoNYKu2B_37OiPIe7xhKUs0BWoBswpMpuwrxmIZKhEHGr_44lDLJGr3mebaKn5BoGro@cipher.nrlssc.navy.mil>
In-Reply-To
<VYN8m1JCy102-eaWWa-bsunEvt3zeXLJkVg7FZKZCtXT-Ww0vg7a8xA7NTvrZTiovKTnJ9Hlom0@cipher.nrlssc.navy.mil>
From: Brandon Casey <drafnel@gmail.com>

The "it" string would not be free'ed if base_name was non-NULL. Let's free it.

Signed-off-by: Brandon Casey <drafnel@gmail.com>
---
 builtin/mv.c |    6 +++++-
 1 files changed, 5 insertions(+), 1 deletions(-)
diff --git a/builtin/mv.c b/builtin/mv.c
index e9d191f..5efe6c5 100644
--- a/builtin/mv.c
+++ b/builtin/mv.c
@@ -29,7 +29,11 @@ static const char **copy_pathspec(const char *prefix, const char **pathspec,
 			to_copy--;
 		if (to_copy != length || base_name) {
 			char *it = xmemdupz(result[i], to_copy);
-			result[i] = base_name ? xstrdup(basename(it)) : it;
+			if (base_name) {
+				result[i] = xstrdup(basename(it));
+				free(it);
+			} else
+				result[i] = it;
 		}
 	}
 	return get_pathspec(prefix, result);
-- 
1.7.7
Previous: Brandon CaseyNext: Brandon Casey
Message 3 of 13 in “attr.c: avoid inappropriate access to strbuf "buf" member”
  1. 1/5 attr.c: avoid inappropriate access to strbuf "buf" memberBrandon Casey, Oct 6, 2011
  2. 2/5 cleanup: use internal memory allocation wrapper functions everywhereBrandon Casey, Oct 6, 2011
  3. 3/5 builtin/mv.c: plug miniscule memory leakBrandon Casey, Oct 6, 2011
  4. 4/5 attr: read core.attributesfile from git_default_core_configBrandon Casey, Oct 6, 2011
  5. 5/5 attr.c: respect core.ignorecase when matching attribute patternsBrandon Casey, Oct 6, 2011
  6. Michael HaggertyOct 9, 2011
  7. Brandon CaseyOct 10, 2011
  8. Michael HaggertyOct 11, 2011
  9. attr.c: respect core.ignorecase when matching attribute patternsBrandon Casey, Oct 11, 2011
  10. Junio C HamanoOct 11, 2011
  11. Brandon CaseyOct 12, 2011
  12. Junio C HamanoOct 12, 2011
  13. Junio C HamanoOct 11, 2011

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.