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

[PATCH] builtin-shortlog.c: do not unnecessarily strdup before insertion in list

From
Adeodato Simó <dato@net.com.org.es>
Date
Dec 24, 2008, 16:34 UTC
Message-ID
<1230136484-12445-1-git-send-email-dato@net.com.org.es>

The log->list always has "strdup_strings" activated, hence strdup'ing namebuf was unnecessary. This change also removes a latent memory leak in the old code.

Signed-off-by: Adeodato Simó <dato@net.com.org.es>
---
 builtin-shortlog.c |    5 +----
 1 files changed, 1 insertions(+), 4 deletions(-)
diff --git a/builtin-shortlog.c b/builtin-shortlog.c
index 4c5d761..90e76ae 100644
--- a/builtin-shortlog.c
+++ b/builtin-shortlog.c
@@ -67,12 +67,9 @@ static void insert_one_record(struct shortlog *log,
 		snprintf(namebuf + len, room, " %.*s", maillen, boemail);
 	}
 
-	buffer = xstrdup(namebuf);
-	item = string_list_insert(buffer, &log->list);
+	item = string_list_insert(namebuf, &log->list);
 	if (item->util == NULL)
 		item->util = xcalloc(1, sizeof(struct string_list));
-	else
-		free(buffer);
 
 	/* Skip any leading whitespace, including any blank lines. */
 	while (*oneline && isspace(*oneline))
-- 
1.6.0.4
Message 1 of 1 in “builtin-shortlog.c: do not unnecessarily strdup before insertion in list”
  1. builtin-shortlog.c: do not unnecessarily strdup before insertion in listAdeodato Simó, Dec 24, 2008

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.