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

Re: [PATCH] reftable: use xmalloc() and xrealloc()

From
Han-Wen Nienhuys <hanwenn@gmail.com>
Date
Apr 8, 2024, 17:50 UTC
Message-ID
<CAOw_e7Z9dGeVU399D6o37L3am0abnYUrZnNQEFKhyUv=A2=j8g@mail.gmail.com>
In-Reply-To
<ZhOETox9FTIOAShN@tanuki>
Op ma 8 apr 2024 07:44 schreef Patrick Steinhardt <ps@pks.im>:
Show 9 quoted lines
>
> It does raise the question what to do about the generic fallbacks. We
> could start calling `abort()` when we observe allocation failures. It's
> not exactly nice behaviour in a library though, where the caller may in
> fact want to handle this case. But it may at least be better than
> failing on a `NULL` pointer exception somewhere down the road. So it
> might be the best alternative for now. We could then conver the reftable
> library over time to handle allocation failures and, once that's done,
> we can eventually drop such a call to `abort()`.

I must admit that I didn't think this part through very much; I believe someone told me that libgit2 has pluggable memory allocation routines, so I tried to make the malloc pluggable here too. Handling OOM better for the malloc calls themselves doesn't seem too difficult,

  hanwen@fedora:~/vc/git/reftable$ grep [cme]alloc *c | wc
     57     276    3469

However, it is probably pointless as long as strbuf_* functions do not signal OOM gracefully. There was some talk of libifying strbuf. Did that work include returning OOM error codes in case malloc returns null? A quick look at strbuf.h suggests not.

I would just call xmalloc as default, rather than calling reftable_set_alloc, because it might be tricky to ensure it is called early enough.

Previous: Patrick SteinhardtNext: Junio C Hamano
Message 5 of 7 in “reftable: use xmalloc() and xrealloc()”
  1. reftable: use xmalloc() and xrealloc()René Scharfe, Apr 6, 2024
  2. Patrick SteinhardtApr 8, 2024
  3. Junio C HamanoApr 8, 2024
  4. Patrick SteinhardtApr 8, 2024
  5. Han-Wen NienhuysApr 8, 2024
  6. Junio C HamanoApr 8, 2024
  7. Patrick SteinhardtApr 9, 2024

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.