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

[PATCH] git.c: two memory leak fixes

From
Alexander Kuleshov <kuleshovmail@gmail.com>
Date
Mar 14, 2015, 18:43 UTC
Message-ID
<1426358613-30180-1-git-send-email-kuleshovmail@gmail.com>

This patch provides fixes for two minor memory leaks in the handle_alias function:

1. We allocate memory for alias_argv with the xmalloc function call,
after run_command_v_opt function will be executed we no need in this
variable anymore, so let's free it.
2. Memory allocated for alias_string variable in the alias_lookup function,
need to free it.
Signed-off-by: Alexander Kuleshov <kuleshovmail@gmail.com>
---
 git.c | 2 ++
 1 file changed, 2 insertions(+)
diff --git a/git.c b/git.c
index 086fac1..501e5bd 100644
--- a/git.c
+++ b/git.c
@@ -252,6 +252,7 @@ static int handle_alias(int *argcp, const char ***argv)
 			alias_argv[argc] = NULL;
 
 			ret = run_command_v_opt(alias_argv, RUN_USING_SHELL);
+			free(alias_argv);
 			if (ret >= 0)   /* normal exit */
 				exit(ret);
 
@@ -259,6 +260,7 @@ static int handle_alias(int *argcp, const char ***argv)
 			    alias_command, alias_string + 1);
 		}
 		count = split_cmdline(alias_string, &new_argv);
+		free(alias_string);
 		if (count < 0)
 			die("Bad alias.%s string: %s", alias_command,
 			    split_cmdline_strerror(count));
-- 
2.3.3.469.g69a3822.dirty
Next: Junio C Hamano
Message 1 of 3 in “git.c: two memory leak fixes”
  1. git.c: two memory leak fixesAlexander Kuleshov, Mar 14, 2015
  2. Junio C HamanoMar 15, 2015
  3. Alexander KuleshovMar 15, 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.