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

[PATCH v2 0/2] Fix a couple small leaks in merge-ort

From
Elijah Newren via GitGitGadget <gitgitgadget@gmail.com>
Date
Feb 20, 2022, 01:29 UTC
Message-ID
<pull.1152.v2.git.1645320591.gitgitgadget@gmail.com>
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
Previous: Elijah NewrenNext: Elijah Newren via GitGitGadget
Message 8 of 15 in “Fix a couple small leaks in merge-ort”
  1. 0/2 Fix a couple small leaks in merge-ortElijah Newren via GitGitGadget, Feb 19, 2022
  2. 1/2 merge-ort: fix small memory leak in detect_and_process_renames()Elijah Newren via GitGitGadget, Feb 19, 2022
  3. Ævar Arnfjörð BjarmasonFeb 19, 2022
  4. Elijah NewrenFeb 20, 2022
  5. 2/2 merge-ort: fix small memory leak in unique_path()Elijah Newren via GitGitGadget, Feb 19, 2022
  6. Ævar Arnfjörð BjarmasonFeb 19, 2022
  7. Elijah NewrenFeb 20, 2022
  8. 0/2 Fix a couple small leaks in merge-ortElijah Newren via GitGitGadget, Feb 20, 2022
  9. 1/2 merge-ort: fix small memory leak in detect_and_process_renames()Elijah Newren via GitGitGadget, Feb 20, 2022
  10. Taylor BlauFeb 21, 2022
  11. Elijah NewrenFeb 23, 2022
  12. Ævar Arnfjörð BjarmasonJun 1, 2022
  13. 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, Jun 1, 2022
  14. 2/2 merge-ort: fix small memory leak in unique_path()Elijah Newren via GitGitGadget, Feb 20, 2022
  15. Taylor BlauFeb 21, 2022

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.