git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
From: Anthony Delannoy <anthony.2lannoy@gmail.com>
To: git@vger.kernel.org
Cc: Anthony Delannoy <anthony.2lannoy@gmail.com>
Subject: [PATCH 1/1] pathspec: fix memleak
Date: Fri, 12 Aug 2022 10:17:44 +0200	[thread overview]
Message-ID: <20220812081744.456280-2-anthony.2lannoy@gmail.com> (raw)
In-Reply-To: <20220812081744.456280-1-anthony.2lannoy@gmail.com>

Fix a memory leak occuring in case of pathspec copy in preload_index.

Direct leak of 8 byte(s) in 8 object(s) allocated from:
    #0 0x7f0a353ead47 in __interceptor_malloc (/usr/lib/gcc/x86_64-pc-linux-gnu/11.3.0/libasan.so.6+0xb5d47)
    #1 0x55750995e840 in do_xmalloc /home/anthony/src/c/git/wrapper.c:51
    #2 0x55750995e840 in xmalloc /home/anthony/src/c/git/wrapper.c:72
    #3 0x55750970f824 in copy_pathspec /home/anthony/src/c/git/pathspec.c:684
    #4 0x557509717278 in preload_index /home/anthony/src/c/git/preload-index.c:135
    #5 0x55750975f21e in refresh_index /home/anthony/src/c/git/read-cache.c:1633
    #6 0x55750915b926 in cmd_status builtin/commit.c:1547
    #7 0x5575090e1680 in run_builtin /home/anthony/src/c/git/git.c:466
    #8 0x5575090e1680 in handle_builtin /home/anthony/src/c/git/git.c:720
    #9 0x5575090e284a in run_argv /home/anthony/src/c/git/git.c:787
    #10 0x5575090e284a in cmd_main /home/anthony/src/c/git/git.c:920
    #11 0x5575090dbf82 in main /home/anthony/src/c/git/common-main.c:56
    #12 0x7f0a348230ab  (/lib64/libc.so.6+0x290ab)

Signed-off-by: Anthony Delannoy <anthony.2lannoy@gmail.com>
---
 preload-index.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/preload-index.c b/preload-index.c
index e5529a5863..a05f4d1390 100644
--- a/preload-index.c
+++ b/preload-index.c
@@ -148,6 +148,9 @@ void preload_index(struct index_state *index,
 		if (pthread_join(p->pthread, NULL))
 			die("unable to join threaded lstat");
 		t2_sum_lstat += p->t2_nr_lstat;
+
+		if (pathspec)
+			free(p->pathspec.items);
 	}
 	stop_progress(&pd.progress);
 
-- 
2.35.1


  reply	other threads:[~2022-08-12  8:17 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-08-12  8:17 [PATCH 0/1] pathspec: fix memleak Anthony Delannoy
2022-08-12  8:17 ` Anthony Delannoy [this message]
2022-08-12 17:41   ` [PATCH 1/1] " Junio C Hamano

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

  List information: http://vger.kernel.org/majordomo-info.html

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20220812081744.456280-2-anthony.2lannoy@gmail.com \
    --to=anthony.2lannoy@gmail.com \
    --cc=git@vger.kernel.org \
    /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.
Code repositories for project(s) associated with this public inbox

	https://80x24.org/mirrors/git.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).