From: Matthieu Moy <Matthieu.Moy@imag.fr>
To: git@vger.kernel.org, gitster@pobox.com
Cc: Matthieu Moy <Matthieu.Moy@imag.fr>
Subject: [PATCH] xmalloc: include size in the failure message
Date: Fri, 20 Aug 2010 17:09:51 +0200 [thread overview]
Message-ID: <1282316991-23320-1-git-send-email-Matthieu.Moy@imag.fr> (raw)
In-Reply-To: <7vhbipcpe1.fsf@alter.siamese.dyndns.org>
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>
---
Junio C Hamano <gitster@pobox.com> writes:
> Matthieu Moy <Matthieu.Moy@imag.fr> writes:
>
>> 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
>
> Unless a single allocation try to grab unreasonably amount of memory,
> probably a failure from a specific single failure may not help much.
I don't promise miracle ;-). But at least, the diagnosis allows one to
distinguish small allocations, huge ones, and silly errors like small
negative numbers turned into unreasonably big ones.
>> if (!ret)
>> - die("Out of memory, malloc failed");
>> + die("Out of memory, malloc failed (tried to allocate %u bytes)", size);
>
> Perhaps use %lu format with cast to ulong?
Will do.
> alloc.c: fix formatting size_t to string
>
> Under NO_C99_FORMAT the format and the argument would not match if size_t
> is not the same size as uint. As the one in sha1_file.c seems to be done
> in a better way, let's use that one.
Sounds good. Not sure why we don't basically use the %lu version
everywhere though.
wrapper.c | 3 ++-
1 files changed, 2 insertions(+), 1 deletions(-)
diff --git a/wrapper.c b/wrapper.c
index afb4f6f..fd8ead3 100644
--- a/wrapper.c
+++ b/wrapper.c
@@ -40,7 +40,8 @@ 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 %lu bytes)",
+ (unsigned long)size);
}
#ifdef XMALLOC_POISON
memset(ret, 0xA5, size);
--
1.7.2.1.83.ge0227
next prev parent reply other threads:[~2010-08-20 15:13 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-08-20 13:01 [PATCH] xmalloc: include size in the failure message Matthieu Moy
2010-08-20 14:47 ` Junio C Hamano
2010-08-20 15:09 ` Matthieu Moy [this message]
2010-08-20 16:31 ` Junio C Hamano
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1282316991-23320-1-git-send-email-Matthieu.Moy@imag.fr \
--to=matthieu.moy@imag.fr \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).