* [PATCH v2 0/1] pathspec: fix memleak
@ 2022-08-22 21:15 Anthony Delannoy
2022-08-22 21:15 ` [PATCH v2 1/1] " Anthony Delannoy
0 siblings, 1 reply; 3+ messages in thread
From: Anthony Delannoy @ 2022-08-22 21:15 UTC (permalink / raw)
To: git; +Cc: Anthony Delannoy
Changes since v1:
- use directly clear_pathspec() function instead of multiple free()
Sending this patch to fix a memleak, created with copy_pathspec, found
thanks to the address sanitizer.
Thanks
Anthony Delannoy (1):
pathspec: fix memleak
preload-index.c | 6 ++++++
1 file changed, 6 insertions(+)
base-commit: 795ea8776befc95ea2becd8020c7a284677b4161
--
2.35.1
^ permalink raw reply [flat|nested] 3+ messages in thread
* [PATCH v2 1/1] pathspec: fix memleak
2022-08-22 21:15 [PATCH v2 0/1] pathspec: fix memleak Anthony Delannoy
@ 2022-08-22 21:15 ` Anthony Delannoy
2022-08-22 21:41 ` Junio C Hamano
0 siblings, 1 reply; 3+ messages in thread
From: Anthony Delannoy @ 2022-08-22 21:15 UTC (permalink / raw)
To: git; +Cc: Anthony Delannoy
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 | 6 ++++++
1 file changed, 6 insertions(+)
diff --git a/preload-index.c b/preload-index.c
index e5529a5863..100f7a374d 100644
--- a/preload-index.c
+++ b/preload-index.c
@@ -151,6 +151,12 @@ void preload_index(struct index_state *index,
}
stop_progress(&pd.progress);
+ if (pathspec) {
+ /* earlier we made deep copies for each thread to work with */
+ for (i = 0; i < threads; i++)
+ clear_pathspec(&data[i].pathspec);
+ }
+
trace_performance_leave("preload index");
trace2_data_intmax("index", NULL, "preload/sum_lstat", t2_sum_lstat);
--
2.35.1
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH v2 1/1] pathspec: fix memleak
2022-08-22 21:15 ` [PATCH v2 1/1] " Anthony Delannoy
@ 2022-08-22 21:41 ` Junio C Hamano
0 siblings, 0 replies; 3+ messages in thread
From: Junio C Hamano @ 2022-08-22 21:41 UTC (permalink / raw)
To: Anthony Delannoy; +Cc: git
Anthony Delannoy <anthony.2lannoy@gmail.com> writes:
> 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 | 6 ++++++
> 1 file changed, 6 insertions(+)
>
> diff --git a/preload-index.c b/preload-index.c
> index e5529a5863..100f7a374d 100644
> --- a/preload-index.c
> +++ b/preload-index.c
> @@ -151,6 +151,12 @@ void preload_index(struct index_state *index,
> }
> stop_progress(&pd.progress);
>
> + if (pathspec) {
> + /* earlier we made deep copies for each thread to work with */
> + for (i = 0; i < threads; i++)
> + clear_pathspec(&data[i].pathspec);
> + }
> +
This round looks good to me.
Thanks, will queue.
> trace_performance_leave("preload index");
>
> trace2_data_intmax("index", NULL, "preload/sum_lstat", t2_sum_lstat);
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2022-08-22 21:41 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-08-22 21:15 [PATCH v2 0/1] pathspec: fix memleak Anthony Delannoy
2022-08-22 21:15 ` [PATCH v2 1/1] " Anthony Delannoy
2022-08-22 21:41 ` Junio C Hamano
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 NNTP newsgroup(s).