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

[PATCH] diff-lib.c: don't strdup twice

From
René Scharfe <rene.scharfe@lsrfire.ath.cx>
Date
Jul 7, 2007, 18:19 UTC
Message-ID
<468FD91C.7040506@lsrfire.ath.cx>

The static function read_directory in diff-lib.c is only ever called with struct path_list lists with .strdup_paths turned on, i.e. path_list_insert will strdup the paths for us (again). Let's take advantage of that and stop doing it twice.

Signed-off-by: Rene Scharfe <rene.scharfe@lsrfire.ath.cx>
---
 diff-lib.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
diff --git a/diff-lib.c b/diff-lib.c
index 7fb19c7..92c0e39 100644
--- a/diff-lib.c
+++ b/diff-lib.c
@@ -24,7 +24,7 @@ static int read_directory(const char *path, struct path_list *list)
 
 	while ((e = readdir(dir)))
 		if (strcmp(".", e->d_name) && strcmp("..", e->d_name))
-			path_list_insert(xstrdup(e->d_name), list);
+			path_list_insert(e->d_name, list);
 
 	closedir(dir);
 	return 0;
Next: Johannes Schindelin
Message 1 of 2 in “diff-lib.c: don't strdup twice”
  1. diff-lib.c: don't strdup twiceRené Scharfe, Jul 7, 2007
  2. Johannes SchindelinJul 7, 2007

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.