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

Re: [PATCH v2] object-file: use real paths when adding alternates

From
Glen Choo <chooglen@google.com>
Date
Nov 24, 2022, 00:50 UTC
Message-ID
<kl6lwn7lch1h.fsf@chooglen-macbookpro.roam.corp.google.com>
In-Reply-To
<Y30onDTUFmAezkSl@coredump.intra.peff.net>
Jeff King <peff@peff.net> writes:
Show 19 quoted lines
>> Doesn't this leak? I've just skimmed strbuf_realpath_1() but e.g. in the
>> "REALPATH_MANY_MISSING" case it'll have allocated the "resolved" (the
>> &tmp you pass in here) and then "does a "goto error_out".
>> 
>> It then *resets* the strbuf, but doesn't release it, assuming that
>> you're going to pass it in again. So in that case we'd leak here, no?
>> 
>> I.e. a NULL return value from strbuf_realpath() doesn't mean that it
>> didn't allocate in the scratch area passed to it, so we need to
>> strbuf_release(&tmp) here too.
>
> We don't use MANY_MISSING in this code path, but I didn't read
> strbuf_realpath_1() carefully enough to see if that is the only case.
> But regardless, I think it is a bug in strbuf_realpath(). All of the
> strbuf functions generally try to leave a buffer untouched on error.
>
> So IMHO we would want a preparatory patch with s/reset/release/ in that
> function, which better matches the intent (we might be freeing an
> allocated buffer, but that's OK from the caller perspective).

Is that always OK? I would think that we'd do something closer to strbuf_getcwd():

  int strbuf_getcwd(struct strbuf *sb)
  {
    size_t oldalloc = sb->alloc;
    /* ... */
    if (oldalloc == 0)
      strbuf_release(sb);
    else
      strbuf_reset(sb);
  }

i.e. if the caller passed in a strbuf with allocated contents, they're responsible for free()-ing it, otherwise we free() it. That does fix the leak in this patch, but I don't feel strongly enough about changing strbuf_realpath() to do it now, so I'll do without the change for now.

Previous: Jeff KingNext: Jeff King
Message 11 of 17 in “object-file: use real paths when adding alternates”
  1. object-file: use real paths when adding alternatesGlen Choo via GitGitGadget, Nov 17, 2022
  2. Jeff KingNov 17, 2022
  3. Ævar Arnfjörð BjarmasonNov 17, 2022
  4. Jeff KingNov 17, 2022
  5. Taylor BlauNov 17, 2022
  6. Glen ChooNov 18, 2022
  7. Taylor BlauNov 17, 2022
  8. object-file: use real paths when adding alternatesGlen Choo via GitGitGadget, Nov 21, 2022
  9. Ævar Arnfjörð BjarmasonNov 22, 2022
  10. Jeff KingNov 22, 2022
  11. Glen ChooNov 24, 2022
  12. Jeff KingNov 24, 2022
  13. Glen ChooNov 24, 2022
  14. Jeff KingNov 22, 2022
  15. object-file: use real paths when adding alternatesGlen Choo via GitGitGadget, Nov 24, 2022
  16. Jeff KingNov 24, 2022
  17. Junio C HamanoNov 25, 2022

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.