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

[PATCH maint] builtin-merge.c: fix memory under-allocation

From
Brandon Casey <casey@nrlssc.navy.mil>
Date
Oct 9, 2008, 00:07 UTC
Message-ID
<ZuhLzndR5Uvj7-_NyasP-FHF3AqTyLx-0sjNHMd0BC3LXC8LdLqBeQ@cipher.nrlssc.navy.mil>

While we're at it, change the allocation to reference the variable it is allocating memory for to try to prevent a similar mistake if the type is changed in the future.

Signed-off-by: Brandon Casey <casey@nrlssc.navy.mil>
---

This causes segfault on IRIX64. I guess the irix compiler doesn't over-allocate memory as aggressively as gcc.

-brandon
 builtin-merge.c |    4 ++--
 1 files changed, 2 insertions(+), 2 deletions(-)
diff --git a/builtin-merge.c b/builtin-merge.c
index dcaf368..d0bf1fc 100644
--- a/builtin-merge.c
+++ b/builtin-merge.c
@@ -651,12 +651,12 @@ static void add_strategies(const char *string, unsigned attr)
 static int merge_trivial(void)
 {
 	unsigned char result_tree[20], result_commit[20];
-	struct commit_list *parent = xmalloc(sizeof(struct commit_list *));
+	struct commit_list *parent = xmalloc(sizeof(*parent));
 
 	write_tree_trivial(result_tree);
 	printf("Wonderful.\n");
 	parent->item = lookup_commit(head);
-	parent->next = xmalloc(sizeof(struct commit_list *));
+	parent->next = xmalloc(sizeof(*parent->next));
 	parent->next->item = remoteheads->item;
 	parent->next->next = NULL;
 	commit_tree(merge_msg.buf, result_tree, parent, result_commit);
-- 
1.6.0.2.446.ge243d
Next: Miklos Vajna
Message 1 of 7 in “builtin-merge.c: fix memory under-allocation”
  1. builtin-merge.c: fix memory under-allocationBrandon Casey, Oct 9, 2008
  2. Miklos VajnaOct 9, 2008
  3. Brandon CaseyOct 9, 2008
  4. Junio C HamanoOct 9, 2008
  5. Brandon CaseyOct 9, 2008
  6. Miklos VajnaOct 9, 2008
  7. Shawn O. PearceOct 9, 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.