git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Alex Riesen <raa.lkml@gmail.com>
To: Jim Meyering <jim@meyering.net>
Cc: git list <git@vger.kernel.org>
Subject: Re: [PATCH] use xstrdup, not strdup in ll-merge.c
Date: Mon, 15 Jun 2009 10:45:22 +0200	[thread overview]
Message-ID: <81b0412b0906150145j7c717a6ar33bb4f2ebd6095e1@mail.gmail.com> (raw)
In-Reply-To: <87fxe2lybr.fsf@meyering.net>

2009/6/15 Jim Meyering <jim@meyering.net>:
> Alex Riesen wrote:
>> 2009/6/14 Jim Meyering <jim@meyering.net>:
>>> @@ -231,7 +231,7 @@ static int read_merge_config(const char *var, const char *value, void *cb)
>>>
>>>        if (!strcmp(var, "merge.default")) {
>>>                if (value)
>>> -                       default_ll_merge = strdup(value);
>>> +                       default_ll_merge = xstrdup(value);
>>
>> read_merge_config has a failure mode (where it returns -1), why not use it?
>
> I didn't even consider it, because it would be inconsistent with
> the other heap-allocation functions used there (xcalloc, xmemdupz).
>
> However, now that I do, it looks like that would mean adding four times
> the same code (including conditionals and code to generate a diagnostic via
> a call to error -- or a goto). Why bother, when all of that is already
> encapsulated in xmalloc?

So that a useful error message can be given in the _caller_ (it knows
more about context)?

Otherwise the error message ("Out of memory, strdup failed") does not
have anything about the place nor situation in it. As the situations
when a modern system really runs out of memory are very rare,
mostly such reports just point at some inconsistency elsewhere
(like bloody stupid memory management in system support libraries
on an OS-not-to-be-named-again or the usual corruption of heap
control structures).

Besides, xstrdup does more then just allocation: it tries to free global
list of cached pack chunks. This does not play very well with the efforts
to make a library out of the modern Git code.

> Maybe because you want to be able to continue after an allocation failure?

No.

> If a small strdup allocation fails, odds are good that the code won't
> be able to do anything useful, so when not in library code, cleanest is
> simply to exit.

Doubt it (because you better describe _why_ you "simply" interrupted
users workflow, so the said user can do something about it).

> In addition, if you insist on using strdup, you'll probably want to
> be consistent and use calloc and memdupz, too.  Adding all of the code
> required to recover from those failures and to avoid leaks would be messy.

I don't insist on that. I should have said in the first message about
more elaborate explanation of the error to user. Sorry.

  reply	other threads:[~2009-06-15  8:45 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-06-14 19:47 [PATCH] use xstrdup, not strdup in ll-merge.c Jim Meyering
2009-06-14 22:03 ` Alex Riesen
2009-06-15  8:02   ` Jim Meyering
2009-06-15  8:45     ` Alex Riesen [this message]
2009-06-15  9:23       ` Jim Meyering
2009-06-15 11:39         ` Alex Riesen
2009-06-15 11:49           ` Jim Meyering
2009-06-15 12:46             ` Alex Riesen
2009-06-15 14:26               ` Shawn O. Pearce
2009-06-15 15:21                 ` Alex Riesen

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=81b0412b0906150145j7c717a6ar33bb4f2ebd6095e1@mail.gmail.com \
    --to=raa.lkml@gmail.com \
    --cc=git@vger.kernel.org \
    --cc=jim@meyering.net \
    /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).