From 1f39afecc00df83ff3306f81716483d843e3f70e Mon Sep 17 00:00:00 2001 From: Robin Watts Date: Tue, 18 Dec 2012 19:22:00 +0000 Subject: Memento: Avoid stack overflows while listing leaked blocks. Leaking long linked lists leads to stack overflows during the Memento debug output. Avoid this by iterating rather than recursing where possible. Also, for sanities sake, where we intent more than 40 spaces, use a single '*' instead. This keeps logfiles sane. --- fitz/memento.c | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/fitz/memento.c b/fitz/memento.c index dcd417b8..7c3c6200 100644 --- a/fitz/memento.c +++ b/fitz/memento.c @@ -474,6 +474,11 @@ static void showBlock(Memento_BlkHeader *b, int space) static void blockDisplay(Memento_BlkHeader *b, int n) { n++; + while (n > 40) + { + fprintf(stderr, "*"); + n -= 40; + } while(n > 0) { int i = n; @@ -499,9 +504,18 @@ static int Memento_listBlock(Memento_BlkHeader *b, static void doNestedDisplay(Memento_BlkHeader *b, int depth) { - blockDisplay(b, depth); - for (b = b->child; b; b = b->sibling) - doNestedDisplay(b, depth+1); + /* Try and avoid recursion if we can help it */ + do { + blockDisplay(b, depth); + if (b->sibling) { + if (b->child) + doNestedDisplay(b->child, depth+1); + b = b->sibling; + } else { + b = b->child; + depth++; + } + } while (b); } static int ptrcmp(const void *a_, const void *b_) -- cgit v1.2.3