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

Re: Proposal/Discussion: Turning parts of Git into libraries

From
Jeff King <peff@peff.net>
Date
Feb 22, 2023, 19:25 UTC
Message-ID
<Y/ZsFuTKyfR+AQy5@coredump.intra.peff.net>
In-Reply-To
<CAJoAoZm+TkCL0Jpg_qFgKottxbtiG2QOiY0qGrz3-uQy+=waPg@mail.gmail.com>
On Tue, Feb 21, 2023 at 02:06:55PM -0800, Emily Shaffer wrote:
> > Does removing memory leaks also mean converting UNLEAK to free()?
> 
> I suspect so - as I understand it, UNLEAK is a macro that resolves to
> "don't complain to me, compiler, I meant not to free it."

Correct. It is supposed to be used sparingly at the outermost level to say "I'm about to exit, so yes, we are leaking this, but no, it does not matter".

So...
Show 10 quoted lines
> > Thinking of things in a library context probably pushes us in that
> > direction (though, alternatively, it might just highlight the question
> > of what is considered "low-level" instead).
> 
> I'm not sure whether use of UNLEAK has so much to do with "low-level"
> or not. In cases when Git is being called as an ephemeral single-run
> process, UNLEAK makes a lot of sense. In cases when Git is being
> called in a long-lived process, UNLEAK is just a sign that says
> "there's a leak here".  So I think the distinction is not low-level or
> high-level, but more simply, within a library or not.

I'd take "low-level" here to mean "far down in the call stack". That is, code which is called potentially from a lot of places, and can't know what is going to happen afterwards.

In that case, such code calling UNLEAK() is already doing the wrong thing. And such code is a likely candidate for being called in a lib-ified long-running process, which means that ignoring the leaks is likely to be more noticeable. :)

There are probably cases where code that is currently high-level becomes more low-level, and will need to be adapted. For example, if cmd_diff() has a static-local helper function for "diff these two blobs", and it knows it will run it exactly once, it is OK to UNLEAK() from there now. But that may be a reasonable API to expose more widely, at which point it needs to stop UNLEAK()-ing and really free.

Just my two cents as the originator of UNLEAK(). :)
-Peff
Previous: Elijah NewrenNext: Taylor Blau
Message 29 of 37 in “Proposal/Discussion: Turning parts of Git into libraries”
  1. Emily ShafferFeb 17, 2023
  2. brian m. carlsonFeb 17, 2023
  3. Emily ShafferFeb 17, 2023
  4. brian m. carlsonFeb 17, 2023
  5. Emily ShafferFeb 17, 2023
  6. Jeff KingFeb 22, 2023
  7. Emily ShafferFeb 24, 2023
  8. Jeff KingFeb 24, 2023
  9. Junio C HamanoFeb 24, 2023
  10. rsbecker@nexbridge.comFeb 17, 2023
  11. brian m. carlsonFeb 17, 2023
  12. Junio C HamanoFeb 17, 2023
  13. demerphqFeb 18, 2023
  14. Phillip WoodFeb 18, 2023
  15. Felipe ContrerasMar 23, 2023
  16. rsbecker@nexbridge.comMar 23, 2023
  17. Felipe ContrerasMar 23, 2023
  18. rsbecker@nexbridge.comMar 23, 2023
  19. Felipe ContrerasMar 23, 2023
  20. rsbecker@nexbridge.comMar 24, 2023
  21. Felipe ContrerasMar 24, 2023
  22. rsbecker@nexbridge.comMar 24, 2023
  23. Felipe ContrerasMar 24, 2023
  24. Emily ShafferFeb 21, 2023
  25. Junio C HamanoFeb 22, 2023
  26. Elijah NewrenFeb 18, 2023
  27. Emily ShafferFeb 21, 2023
  28. Elijah NewrenFeb 22, 2023
  29. Jeff KingFeb 22, 2023
  30. Taylor BlauFeb 21, 2023
  31. Emily ShafferFeb 21, 2023
  32. Victoria DyeFeb 22, 2023
  33. Jonathan TanFeb 25, 2023
  34. Derrick StoleeFeb 22, 2023
  35. Emily ShafferFeb 24, 2023
  36. Felipe ContrerasMar 23, 2023
  37. rsbecker@nexbridge.comMar 23, 2023

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.