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

Re: git fsck segmentation fault

From
MKMartin Koegler <mkoegler@auto.tuwien.ac.at>
Date
Dec 10, 2008, 07:53 UTC
Message-ID
<20081210075338.GA7776@auto.tuwien.ac.at>
In-Reply-To
<alpine.LFD.2.00.0812091408560.14328@xanadu.home>
Maybe something like this could help:
>From 32be177cbb0825fc019200b172f3d79117b28140 Mon Sep 17 00:00:00 2001
From: Martin Koegler <mkoegler@auto.tuwien.ac.at>
Date: Wed, 10 Dec 2008 08:42:08 +0100
Subject: [PATCH] fsck: use fewer stack

This patch moves the state while traversing the tree from the stack to the heap.

Not-really-tested-by: Martin Koegler
Signed-off-by: Martin Koegler <mkoegler@auto.tuwien.ac.at>
---
 builtin-fsck.c |   19 +++++++++++++++++--
 1 files changed, 17 insertions(+), 2 deletions(-)
diff --git a/builtin-fsck.c b/builtin-fsck.c
index afded5e..8184699 100644
--- a/builtin-fsck.c
+++ b/builtin-fsck.c
@@ -36,6 +36,9 @@ static int verbose;
 #define DIRENT_SORT_HINT(de) ((de)->d_ino)
 #endif
 
+static int objectstack_nr, objectstack_alloc;
+struct object **objectstack;
+
 static void objreport(struct object *obj, const char *severity,
                       const char *err, va_list params)
 {
@@ -66,9 +69,7 @@ static int fsck_error_func(struct object *obj, int type, const char *err, ...)
 
 static int mark_object(struct object *obj, int type, void *data)
 {
-	struct tree *tree = NULL;
 	struct object *parent = data;
-	int result;
 
 	if (!obj) {
 		printf("broken link from %7s %s\n",
@@ -95,6 +96,15 @@ static int mark_object(struct object *obj, int type, void *data)
 		}
 		return 1;
 	}
+	ALLOC_GROW(objectstack, objectstack_nr + 1, objectstack_alloc);
+	objectstack[objectstack_nr++] = obj;
+	return 0;
+}
+
+static int mark_child_object(struct object *obj)
+{
+	struct tree *tree = NULL;
+	int result;
 
 	if (obj->type == OBJ_TREE) {
 		obj->parsed = 0;
@@ -116,6 +126,11 @@ static int mark_object(struct object *obj, int type, void *data)
 static void mark_object_reachable(struct object *obj)
 {
 	mark_object(obj, OBJ_ANY, 0);
+	while (objectstack_nr > 0) {
+		struct object *obj = objectstack[--objectstack_nr];
+		if (mark_child_object(obj) < 0)
+			break;
+	}
 }
 
 static int mark_used(struct object *obj, int type, void *data)
-- 
1.6.1.rc2.283.g32be1
Previous: Martin KoeglerNext: Junio C Hamano
Message 9 of 12 in “git fsck segmentation fault”
  1. Simon HausmannNov 27, 2008
  2. Nicolas PitreNov 27, 2008
  3. Simon HausmannNov 27, 2008
  4. Simon HausmannNov 27, 2008
  5. Nicolas PitreNov 27, 2008
  6. Simon HausmannNov 28, 2008
  7. Nicolas PitreDec 9, 2008
  8. Martin KoeglerDec 9, 2008
  9. Martin KoeglerDec 10, 2008
  10. Junio C HamanoDec 11, 2008
  11. Martin KoeglerDec 11, 2008
  12. Junio C HamanoDec 11, 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.