From: "Elijah Newren via GitGitGadget" <gitgitgadget@gmail.com>
To: git@vger.kernel.org
Cc: "Ævar Arnfjörð Bjarmason" <avarab@gmail.com>,
"Elijah Newren" <newren@gmail.com>
Subject: [PATCH v2 0/2] Fix a couple small leaks in merge-ort
Date: Sun, 20 Feb 2022 01:29:49 +0000 [thread overview]
Message-ID: <pull.1152.v2.git.1645320591.gitgitgadget@gmail.com> (raw)
In-Reply-To: <pull.1152.git.1645290601.gitgitgadget@gmail.com>
Off-list, Ævar reported a few small leaks in merge-ort to me that I missed
previously. Here's a couple fixes.
Changes since v1:
* Simplified patch 1 a bit as per Ævar's suggestion
Elijah Newren (2):
merge-ort: fix small memory leak in detect_and_process_renames()
merge-ort: fix small memory leak in unique_path()
merge-ort.c | 36 +++++++++++++++++-------------------
1 file changed, 17 insertions(+), 19 deletions(-)
base-commit: e2ac9141e64e2cd3e690d1b5fc848949827c09b4
Published-As: https://github.com/gitgitgadget/git/releases/tag/pr-1152%2Fnewren%2Fmerge-ort-leak-fixes-v2
Fetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-1152/newren/merge-ort-leak-fixes-v2
Pull-Request: https://github.com/gitgitgadget/git/pull/1152
Range-diff vs v1:
1: f0308de28e4 ! 1: f1f7fc97fe2 merge-ort: fix small memory leak in detect_and_process_renames()
@@ Commit message
free(combined.queue);
}
- The problem is that sometimes even when there are pairs, none of them are
- necessary. Instead of checking combined.nr, we should check
- combined.alloc. Doing so fixes the following memory leak, as reported
- by valgrind:
+ The problem is that sometimes even when there are pairs, none of them
+ are necessary. Instead of checking combined.nr, just remove the
+ if-check; free() knows to skip NULL pointers. This change fixes the
+ following memory leak, as reported by valgrind:
==PID== 192 bytes in 1 blocks are definitely lost in loss record 107 of 134
==PID== at 0xADDRESS: malloc
@@ Commit message
Signed-off-by: Elijah Newren <newren@gmail.com>
## merge-ort.c ##
+@@ merge-ort.c: static int detect_and_process_renames(struct merge_options *opt,
+ struct tree *side1,
+ struct tree *side2)
+ {
+- struct diff_queue_struct combined;
++ struct diff_queue_struct combined = { 0 };
+ struct rename_info *renames = &opt->priv->renames;
+- int need_dir_renames, s, clean = 1;
++ int need_dir_renames, s, i, clean = 1;
+ unsigned detection_run = 0;
+
+- memset(&combined, 0, sizeof(combined));
+ if (!possible_renames(renames))
+ goto cleanup;
+
@@ merge-ort.c: simple_cleanup:
free(renames->pairs[s].queue);
DIFF_QUEUE_CLEAR(&renames->pairs[s]);
}
- if (combined.nr) {
-+ if (combined.alloc) {
- int i;
- for (i = 0; i < combined.nr; i++)
- pool_diff_free_filepair(&opt->priv->pool,
+- int i;
+- for (i = 0; i < combined.nr; i++)
+- pool_diff_free_filepair(&opt->priv->pool,
+- combined.queue[i]);
+- free(combined.queue);
+- }
++ for (i = 0; i < combined.nr; i++)
++ pool_diff_free_filepair(&opt->priv->pool, combined.queue[i]);
++ free(combined.queue);
+
+ return clean;
+ }
2: 73bc1e5c5df = 2: 69fb932c21d merge-ort: fix small memory leak in unique_path()
--
gitgitgadget
next prev parent reply other threads:[~2022-02-20 1:29 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-02-19 17:09 [PATCH 0/2] Fix a couple small leaks in merge-ort Elijah Newren via GitGitGadget
2022-02-19 17:09 ` [PATCH 1/2] merge-ort: fix small memory leak in detect_and_process_renames() Elijah Newren via GitGitGadget
2022-02-19 21:44 ` Ævar Arnfjörð Bjarmason
2022-02-20 0:26 ` Elijah Newren
2022-02-19 17:10 ` [PATCH 2/2] merge-ort: fix small memory leak in unique_path() Elijah Newren via GitGitGadget
2022-02-19 22:22 ` Ævar Arnfjörð Bjarmason
2022-02-20 0:37 ` Elijah Newren
2022-02-20 1:29 ` Elijah Newren via GitGitGadget [this message]
2022-02-20 1:29 ` [PATCH v2 1/2] merge-ort: fix small memory leak in detect_and_process_renames() Elijah Newren via GitGitGadget
2022-02-21 2:35 ` Taylor Blau
2022-02-23 7:57 ` Elijah Newren
2022-06-01 10:00 ` Ævar Arnfjörð Bjarmason
2022-06-01 10:09 ` Flaky SANITIZE=leak test "regression" in v2.36.0 (was: [PATCH v2 1/2] merge-ort: fix small memory leak in detect_and_process_renames()) Ævar Arnfjörð Bjarmason
2022-02-20 1:29 ` [PATCH v2 2/2] merge-ort: fix small memory leak in unique_path() Elijah Newren via GitGitGadget
2022-02-21 2:43 ` [PATCH v2 0/2] Fix a couple small leaks in merge-ort Taylor Blau
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=pull.1152.v2.git.1645320591.gitgitgadget@gmail.com \
--to=gitgitgadget@gmail.com \
--cc=avarab@gmail.com \
--cc=git@vger.kernel.org \
--cc=newren@gmail.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.