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

[PATCH 7/6] argv-array: drop "detach" code

From
Jeff King <peff@peff.net>
Date
May 15, 2014, 08:41 UTC
Message-ID
<20140515084102.GA28461@sigill.intra.peff.net>
In-Reply-To
<20140515082943.GA26473@sigill.intra.peff.net>

The argv_array_detach function (and associated free() function) was really only useful for transferring ownership of the memory to a "struct child_process". Now that we have an internal argv_array in that struct, there are no callers left.

Signed-off-by: Jeff King <peff@peff.net>
---
This is a bonus enabled by the earlier patches. However, there is one
commit in pu that uses it when dealing with environment variables.
However, it is actually leaking memory, and should probably just use the
array directly (and it's one of my commits that's due to be re-rolled
anyway).
 Documentation/technical/api-argv-array.txt |  8 --------
 argv-array.c                               | 20 --------------------
 argv-array.h                               |  2 --
 3 files changed, 30 deletions(-)
diff --git a/Documentation/technical/api-argv-array.txt b/Documentation/technical/api-argv-array.txt
index a6b7d83..1a79781 100644
--- a/Documentation/technical/api-argv-array.txt
+++ b/Documentation/technical/api-argv-array.txt
@@ -53,11 +53,3 @@ Functions
 `argv_array_clear`::
 	Free all memory associated with the array and return it to the
 	initial, empty state.
-
-`argv_array_detach`::
-	Detach the argv array from the `struct argv_array`, transferring
-	ownership of the allocated array and strings.
-
-`argv_array_free_detached`::
-	Free the memory allocated by a `struct argv_array` that was later
-	detached and is now no longer needed.
diff --git a/argv-array.c b/argv-array.c
index 9e960d5..256741d 100644
--- a/argv-array.c
+++ b/argv-array.c
@@ -68,23 +68,3 @@ void argv_array_clear(struct argv_array *array)
 	}
 	argv_array_init(array);
 }
-
-const char **argv_array_detach(struct argv_array *array, int *argc)
-{
-	const char **argv =
-		array->argv == empty_argv || array->argc == 0 ? NULL : array->argv;
-	if (argc)
-		*argc = array->argc;
-	argv_array_init(array);
-	return argv;
-}
-
-void argv_array_free_detached(const char **argv)
-{
-	if (argv) {
-		int i;
-		for (i = 0; argv[i]; i++)
-			free((char **)argv[i]);
-		free(argv);
-	}
-}
diff --git a/argv-array.h b/argv-array.h
index 85ba438..c65e6e8 100644
--- a/argv-array.h
+++ b/argv-array.h
@@ -19,7 +19,5 @@ LAST_ARG_MUST_BE_NULL
 void argv_array_pushl(struct argv_array *, ...);
 void argv_array_pop(struct argv_array *);
 void argv_array_clear(struct argv_array *);
-const char **argv_array_detach(struct argv_array *array, int *argc);
-void argv_array_free_detached(const char **argv);
 
 #endif /* ARGV_ARRAY_H */
-- 
2.0.0.rc1.436.g03cb729
Previous: Jeff KingNext: Junio C Hamano
Message 8 of 9 in “build argv_array into run-command”
  1. 0/6 build argv_array into run-commandJeff King, May 15, 2014
  2. 1/6 run-command: store an optional argv_arrayJeff King, May 15, 2014
  3. 2/6 run_column_filter: use argv_arrayJeff King, May 15, 2014
  4. 3/6 git_connect: use argv_arrayJeff King, May 15, 2014
  5. 4/6 get_helper: use run-command's internal argv_arrayJeff King, May 15, 2014
  6. 5/6 get_exporter: use argv_arrayJeff King, May 15, 2014
  7. 6/6 get_importer: use run-command's internal argv_arrayJeff King, May 15, 2014
  8. 7/6 argv-array: drop "detach" codeJeff King, May 15, 2014
  9. Junio C HamanoMay 15, 2014

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.