{"thread":{"id":"58346","subject":"[PATCH v2 0/1] pathspec: fix memleak","startedAt":"2022-08-22T21:15:16Z","lastAt":"2022-08-22T21:41:27Z","messageCount":3,"participants":["Anthony Delannoy","Junio C Hamano"],"isPatch":true,"patchVersion":2,"patchTotal":1},"messages":[{"id":"461811","messageId":"20220822211507.8693-1-anthony.2lannoy@gmail.com","threadId":"58346","inReplyTo":null,"subject":"[PATCH v2 0/1] pathspec: fix memleak","fromName":"Anthony Delannoy","fromEmail":"anthony.2lannoy@gmail.com","sentAt":"2022-08-22T21:15:06Z","receivedAt":"2022-08-22T21:15:16Z","isPatch":true,"sender":{"key":"anthony.2lannoy@gmail.com","avatar":"https://avatars.githubusercontent.com/u/32701669?v=4"},"body":"Changes since v1:\n- use directly clear_pathspec() function instead of multiple free()\n\nSending this patch to fix a memleak, created with copy_pathspec, found\nthanks to the address sanitizer.\n\nThanks\n\nAnthony Delannoy (1):\n  pathspec: fix memleak\n\n preload-index.c | 6 ++++++\n 1 file changed, 6 insertions(+)\n\n\nbase-commit: 795ea8776befc95ea2becd8020c7a284677b4161\n--\n2.35.1\n"},{"id":"461812","messageId":"20220822211507.8693-2-anthony.2lannoy@gmail.com","threadId":"58346","inReplyTo":"20220822211507.8693-1-anthony.2lannoy@gmail.com","subject":"[PATCH v2 1/1] pathspec: fix memleak","fromName":"Anthony Delannoy","fromEmail":"anthony.2lannoy@gmail.com","sentAt":"2022-08-22T21:15:07Z","receivedAt":"2022-08-22T21:15:19Z","isPatch":true,"sender":{"key":"anthony.2lannoy@gmail.com","avatar":"https://avatars.githubusercontent.com/u/32701669?v=4"},"body":"Fix a memory leak occuring in case of pathspec copy in preload_index.\n\nDirect leak of 8 byte(s) in 8 object(s) allocated from:\n    #0 0x7f0a353ead47 in __interceptor_malloc (/usr/lib/gcc/x86_64-pc-linux-gnu/11.3.0/libasan.so.6+0xb5d47)\n    #1 0x55750995e840 in do_xmalloc /home/anthony/src/c/git/wrapper.c:51\n    #2 0x55750995e840 in xmalloc /home/anthony/src/c/git/wrapper.c:72\n    #3 0x55750970f824 in copy_pathspec /home/anthony/src/c/git/pathspec.c:684\n    #4 0x557509717278 in preload_index /home/anthony/src/c/git/preload-index.c:135\n    #5 0x55750975f21e in refresh_index /home/anthony/src/c/git/read-cache.c:1633\n    #6 0x55750915b926 in cmd_status builtin/commit.c:1547\n    #7 0x5575090e1680 in run_builtin /home/anthony/src/c/git/git.c:466\n    #8 0x5575090e1680 in handle_builtin /home/anthony/src/c/git/git.c:720\n    #9 0x5575090e284a in run_argv /home/anthony/src/c/git/git.c:787\n    #10 0x5575090e284a in cmd_main /home/anthony/src/c/git/git.c:920\n    #11 0x5575090dbf82 in main /home/anthony/src/c/git/common-main.c:56\n    #12 0x7f0a348230ab  (/lib64/libc.so.6+0x290ab)\n\nSigned-off-by: Anthony Delannoy <anthony.2lannoy@gmail.com>\n---\n preload-index.c | 6 ++++++\n 1 file changed, 6 insertions(+)\n\ndiff --git a/preload-index.c b/preload-index.c\nindex e5529a5863..100f7a374d 100644\n--- a/preload-index.c\n+++ b/preload-index.c\n@@ -151,6 +151,12 @@ void preload_index(struct index_state *index,\n \t}\n \tstop_progress(&pd.progress);\n \n+\tif (pathspec) {\n+\t\t/* earlier we made deep copies for each thread to work with */\n+\t\tfor (i = 0; i < threads; i++)\n+\t\t\tclear_pathspec(&data[i].pathspec);\n+\t}\n+\n \ttrace_performance_leave(\"preload index\");\n \n \ttrace2_data_intmax(\"index\", NULL, \"preload/sum_lstat\", t2_sum_lstat);\n-- \n2.35.1\n\n"},{"id":"461815","messageId":"xmqq4jy4ard4.fsf@gitster.g","threadId":"58346","inReplyTo":"20220822211507.8693-2-anthony.2lannoy@gmail.com","subject":"Re: [PATCH v2 1/1] pathspec: fix memleak","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2022-08-22T21:41:11Z","receivedAt":"2022-08-22T21:41:27Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Anthony Delannoy <anthony.2lannoy@gmail.com> writes:\n\n> Fix a memory leak occuring in case of pathspec copy in preload_index.\n>\n> Direct leak of 8 byte(s) in 8 object(s) allocated from:\n>     #0 0x7f0a353ead47 in __interceptor_malloc (/usr/lib/gcc/x86_64-pc-linux-gnu/11.3.0/libasan.so.6+0xb5d47)\n>     #1 0x55750995e840 in do_xmalloc /home/anthony/src/c/git/wrapper.c:51\n>     #2 0x55750995e840 in xmalloc /home/anthony/src/c/git/wrapper.c:72\n>     #3 0x55750970f824 in copy_pathspec /home/anthony/src/c/git/pathspec.c:684\n>     #4 0x557509717278 in preload_index /home/anthony/src/c/git/preload-index.c:135\n>     #5 0x55750975f21e in refresh_index /home/anthony/src/c/git/read-cache.c:1633\n>     #6 0x55750915b926 in cmd_status builtin/commit.c:1547\n>     #7 0x5575090e1680 in run_builtin /home/anthony/src/c/git/git.c:466\n>     #8 0x5575090e1680 in handle_builtin /home/anthony/src/c/git/git.c:720\n>     #9 0x5575090e284a in run_argv /home/anthony/src/c/git/git.c:787\n>     #10 0x5575090e284a in cmd_main /home/anthony/src/c/git/git.c:920\n>     #11 0x5575090dbf82 in main /home/anthony/src/c/git/common-main.c:56\n>     #12 0x7f0a348230ab  (/lib64/libc.so.6+0x290ab)\n>\n> Signed-off-by: Anthony Delannoy <anthony.2lannoy@gmail.com>\n> ---\n>  preload-index.c | 6 ++++++\n>  1 file changed, 6 insertions(+)\n>\n> diff --git a/preload-index.c b/preload-index.c\n> index e5529a5863..100f7a374d 100644\n> --- a/preload-index.c\n> +++ b/preload-index.c\n> @@ -151,6 +151,12 @@ void preload_index(struct index_state *index,\n>  \t}\n>  \tstop_progress(&pd.progress);\n>  \n> +\tif (pathspec) {\n> +\t\t/* earlier we made deep copies for each thread to work with */\n> +\t\tfor (i = 0; i < threads; i++)\n> +\t\t\tclear_pathspec(&data[i].pathspec);\n> +\t}\n> +\n\nThis round looks good to me.\n\nThanks, will queue.\n\n>  \ttrace_performance_leave(\"preload index\");\n>  \n>  \ttrace2_data_intmax(\"index\", NULL, \"preload/sum_lstat\", t2_sum_lstat);\n"}]}