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

Re: [PATCH 17/23] midx-write: fix leaking buffer

From
Taylor Blau <me@ttaylorr.com>
Date
Sep 30, 2024, 21:27 UTC
Message-ID
<ZvsXrQadrU78rEha@nand.local>
In-Reply-To
<5db4e17db9b9b991e0dbe56d7043b56e5d161097.1727687410.git.ps@pks.im>
On Mon, Sep 30, 2024 at 11:14:01AM +0200, Patrick Steinhardt wrote:
Show 15 quoted lines
> The buffer used to compute the final MIDX name is never released. Plug
> this memory leak.
>
> Signed-off-by: Patrick Steinhardt <ps@pks.im>
> ---
>  midx-write.c                            | 2 ++
>  t/t5334-incremental-multi-pack-index.sh | 2 ++
>  2 files changed, 4 insertions(+)
>
> diff --git a/midx-write.c b/midx-write.c
> index 1ef62c4f4b..625c7d3137 100644
> --- a/midx-write.c
> +++ b/midx-write.c
> @@ -1445,6 +1445,8 @@ static int write_midx_internal(const char *object_dir,
>  			return -1;

Would you also want to strbuf_release() the final_midx_name buffer here as well?

I guess the point is moot since there are a number of other finalization steps that we likewise skip here by returning -1 directly instead of jumping to the cleanup sub-routine.

In the above sense I'm OK with it as-is, but it would be nice to verify that this portion of the code is leak-free even when we return early (e.g., because we couldn't rename() the tempfile into place).

Of course, because final_midx_name is local to the body of this conditional, I think you'd need to do something like:

    if (ctx.incremntal) {
        struct strbuf final_midx_name = STRBUF_INIT;
        /* ... */
        get_split_midx_filename_ext(&final_midx_name, object_dir,
                                    midx_hash, MIDX_EXT_MIDX);
        if (rename_tempfile(&incr, final_midx_name.buf) < 0) {
            result = error_errno(_("unable to rename new multi-pack-index layer"));
            strbuf_release(&final_midx_name); /* <- here */
            goto cleanup;
        }
        strbuf_release(&final_midx_name); /* ... <- and here */
        keep_hashes[ctx.num_multi_pack_indexes_before] =
          xstrdup(hash_to_hex(midx_hash));
    }

Thanks, Taylor

Previous: Patrick SteinhardtNext: Patrick Steinhardt
Message 26 of 33 in “Memory leak fixes (pt.8)”
  1. 00/23 Memory leak fixes (pt.8)Patrick Steinhardt, Sep 30, 2024
  2. 01/23 builtin/annotate: fix leaking args vectorPatrick Steinhardt, Sep 30, 2024
  3. 02/23 read-cache: fix leaking hash context in `do_write_index()`Patrick Steinhardt, Sep 30, 2024
  4. Derrick StoleeSep 30, 2024
  5. 03/23 scalar: fix leaking repositoriesPatrick Steinhardt, Sep 30, 2024
  6. 04/23 shell: fix leaking stringsPatrick Steinhardt, Sep 30, 2024
  7. 05/23 wt-status: fix leaking buffer with sparse directoriesPatrick Steinhardt, Sep 30, 2024
  8. 06/23 submodule: fix leaking submodule entry listPatrick Steinhardt, Sep 30, 2024
  9. 07/23 builtin/stash: fix leaking `pathspec_from_file`Patrick Steinhardt, Sep 30, 2024
  10. 08/23 builtin/pack-redundant: fix various memory leaksPatrick Steinhardt, Sep 30, 2024
  11. 09/23 builtin/clone: fix leaking repo state when cloning with bundle URIsPatrick Steinhardt, Sep 30, 2024
  12. 10/23 t/helper: fix leaking repository in partial-clone helperPatrick Steinhardt, Sep 30, 2024
  13. 11/23 builtin/revert: fix leaking `gpg_sign` and `strategy` configPatrick Steinhardt, Sep 30, 2024
  14. 12/23 diff: improve lifecycle management of diff queuesPatrick Steinhardt, Sep 30, 2024
  15. 13/23 line-log: fix several memory leaksPatrick Steinhardt, Sep 30, 2024
  16. 14/23 pseudo-merge: fix various memory leaksPatrick Steinhardt, Sep 30, 2024
  17. Taylor BlauSep 30, 2024
  18. 15/23 pseudo-merge: fix leaking strmap keysPatrick Steinhardt, Sep 30, 2024
  19. Taylor BlauSep 30, 2024
  20. Patrick SteinhardtOct 7, 2024
  21. Jeff KingOct 8, 2024
  22. Patrick SteinhardtOct 9, 2024
  23. 16/23 pack-bitmap-write: fix leaking OID arrayPatrick Steinhardt, Sep 30, 2024
  24. Taylor BlauSep 30, 2024
  25. 17/23 midx-write: fix leaking bufferPatrick Steinhardt, Sep 30, 2024
  26. Taylor BlauSep 30, 2024
  27. Patrick SteinhardtOct 7, 2024
  28. 18/23 revision: fix memory leaks when rewriting parentsPatrick Steinhardt, Sep 30, 2024
  29. 19/23 revision: fix leaking saved parentsPatrick Steinhardt, Sep 30, 2024
  30. 20/23 pack-write: fix return parameter of `write_rev_file_order()`Patrick Steinhardt, Sep 30, 2024
  31. 21/23 t/helper: fix leaks in proc-receive helperPatrick Steinhardt, Sep 30, 2024
  32. 22/23 remote: fix leaking push reportsPatrick Steinhardt, Sep 30, 2024
  33. 23/23 builtin/send-pack: fix leaking list of push optionsPatrick Steinhardt, Sep 30, 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.