[PATCH] xmalloc: include size in the failure message

Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]
From: Matthieu Moy
Date: Friday, August 20, 2010 - 6:01 am

Out-of-memory errors can either be actual lack of memory, or bugs (like
code trying to call xmalloc(-1) by mistake). A little more information
may help tracking bugs reported by users.

Signed-off-by: Matthieu Moy <Matthieu.Moy@imag.fr>
---
This kind of thing may help for cases like

Subject: Out of memory error during git push
http://thread.gmane.org/gmane.comp.version-control.git/153988

 wrapper.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)

diff --git a/wrapper.c b/wrapper.c
index afb4f6f..7057cbd 100644
--- a/wrapper.c
+++ b/wrapper.c
@@ -40,7 +40,7 @@ void *xmalloc(size_t size)
 		if (!ret && !size)
 			ret = malloc(1);
 		if (!ret)
-			die("Out of memory, malloc failed");
+			die("Out of memory, malloc failed (tried to allocate %u bytes)", size);
 	}
 #ifdef XMALLOC_POISON
 	memset(ret, 0xA5, size);
-- 
1.7.2.1.83.ge0227

--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]

Messages in current thread:
[PATCH] xmalloc: include size in the failure message, Matthieu Moy, (Fri Aug 20, 6:01 am)
Re: [PATCH] xmalloc: include size in the failure message, Junio C Hamano, (Fri Aug 20, 7:47 am)
[PATCH] xmalloc: include size in the failure message, Matthieu Moy, (Fri Aug 20, 8:09 am)
Re: [PATCH] xmalloc: include size in the failure message, Junio C Hamano, (Fri Aug 20, 9:31 am)