From: "Martin Ågren" <martin.agren@gmail.com>
To: gitgitgadget@gmail.com
Cc: Git Mailing List <git@vger.kernel.org>,
Junio C Hamano <gitster@pobox.com>,
Derrick Stolee <dstolee@microsoft.com>
Subject: Re: [PATCH 1/2] commit-graph: clean up leaked memory during write
Date: Tue, 2 Oct 2018 17:40:01 +0200 [thread overview]
Message-ID: <CAN0heSomOen+mWg1CuPGUCJFgmDQUjGLtAdxpWLwrStRU4Me8g@mail.gmail.com> (raw)
In-Reply-To: <6906c25415eddf79cc3f71f905a77b140f2f66f0.1538492321.git.gitgitgadget@gmail.com>
On Tue, 2 Oct 2018 at 17:01, Derrick Stolee via GitGitGadget
<gitgitgadget@gmail.com> wrote:
> diff --git a/commit-graph.c b/commit-graph.c
> index 2a24eb8b5a..7226bd6b58 100644
> --- a/commit-graph.c
> +++ b/commit-graph.c
> @@ -698,6 +698,8 @@ void write_commit_graph_reachable(const char *obj_dir, int append,
> string_list_init(&list, 1);
> for_each_ref(add_ref_to_list, &list);
> write_commit_graph(obj_dir, NULL, &list, append, report_progress);
> +
> + string_list_clear(&list, 0);
> }
Nit: The blank line adds some asymmetry, IMVHO.
> void write_commit_graph(const char *obj_dir,
> @@ -846,9 +848,11 @@ void write_commit_graph(const char *obj_dir,
> compute_generation_numbers(&commits, report_progress);
>
> graph_name = get_commit_graph_filename(obj_dir);
> - if (safe_create_leading_directories(graph_name))
> + if (safe_create_leading_directories(graph_name)) {
> + UNLEAK(graph_name);
> die_errno(_("unable to create leading directories of %s"),
> graph_name);
> + }
Do you really need this hunk? In my testing with LeakSanitizer and
valgrind, I don't need this hunk to be leak-free. Generally speaking, it
seems impossible to UNLEAK when dying, since we don't know what we have
allocated higher up in the call-stack.
Without this hunk, this patch can have my
Reviewed-by: Martin Ågren <martin.agren@gmail.com>
as I've verified the leaks before and after. With this hunk, I am
puzzled and feel uneasy, both about having to UNLEAK before dying and
about having to UNLEAK outside of builtin/.
> + free(graph_name);
> + free(commits.list);
> free(oids.list);
> oids.alloc = 0;
> oids.nr = 0;
Both `commits` and `oids` are on the stack here, so cleaning up one more
than the other is a bit asymmetrical. Also, if we try to zero the counts
-- which seems unnecessary to me, but which is not new with this patch --
we should perhaps use `FREE_AND_NULL` too. But personally, I would just
use `free` and leave `nr` and `alloc` at whatever values they happen to
have.
Martin
next prev parent reply other threads:[~2018-10-02 15:40 UTC|newest]
Thread overview: 20+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-10-02 14:58 [PATCH 0/2] Clean up leaks in commit-graph.c Derrick Stolee via GitGitGadget
2018-10-02 14:58 ` [PATCH 1/2] commit-graph: clean up leaked memory during write Derrick Stolee via GitGitGadget
2018-10-02 15:40 ` Martin Ågren [this message]
2018-10-02 17:59 ` Stefan Beller
2018-10-02 19:08 ` Martin Ågren
2018-10-02 19:44 ` Stefan Beller
2018-10-02 22:34 ` Jeff King
2018-10-02 22:44 ` Stefan Beller
2018-10-03 12:04 ` Derrick Stolee
2018-10-03 15:36 ` [PATCH 0/2] commit-graph: more leak fixes Martin Ågren
2018-10-03 15:36 ` [PATCH 1/2] commit-graph: free `struct packed_git` after closing it Martin Ågren
2018-10-03 15:36 ` [PATCH 2/2] builtin/commit-graph.c: UNLEAK variables Martin Ågren
2018-10-03 16:19 ` [PATCH 0/2] commit-graph: more leak fixes Derrick Stolee
2018-10-03 16:24 ` Martin Ågren
2018-10-02 22:37 ` [PATCH 1/2] commit-graph: clean up leaked memory during write Jeff King
2018-10-02 14:58 ` [PATCH 2/2] commit-graph: reduce initial oid allocation Derrick Stolee via GitGitGadget
2018-10-03 17:12 ` [PATCH v2 0/3] Clean up leaks in commit-graph.c Derrick Stolee via GitGitGadget
2018-10-03 17:12 ` [PATCH v2 1/3] commit-graph: clean up leaked memory during write Derrick Stolee via GitGitGadget
2018-10-03 17:12 ` [PATCH v2 2/3] builtin/commit-graph.c: UNLEAK variables Martin Ågren via GitGitGadget
2018-10-03 17:12 ` [PATCH v2 3/3] commit-graph: reduce initial oid allocation Derrick Stolee via GitGitGadget
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=CAN0heSomOen+mWg1CuPGUCJFgmDQUjGLtAdxpWLwrStRU4Me8g@mail.gmail.com \
--to=martin.agren@gmail.com \
--cc=dstolee@microsoft.com \
--cc=git@vger.kernel.org \
--cc=gitgitgadget@gmail.com \
--cc=gitster@pobox.com \
/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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.