From: "lilinchao@oschina.cn" <lilinchao@oschina.cn> To: "Lénaïc Huard" <lenaic@lhuard.fr>, git <git@vger.kernel.org> Cc: "Junio C Hamano" <gitster@pobox.com>, "Derrick Stolee" <dstolee@microsoft.com>, "Eric Sunshine" <sunshine@sunshineco.com>, "Lénaïc Huard" <lenaic@lhuard.fr> Subject: Re: [PATCH] maintenance: fix two memory leaks Date: Mon, 10 May 2021 14:38:56 +0800 [thread overview] Message-ID: <67ed4ca6b15a11eba8d80024e87935e7@oschina.cn> (raw) In-Reply-To: <20210509221613.474887-1-lenaic@lhuard.fr> Hi, >Fixes two memory leaks when running `git maintenance start` or `git >maintenance stop` in `update_background_schedule`: > >$ valgrind --leak-check=full ~/git/bin/git maintenance start >==76584== Memcheck, a memory error detector >==76584== Copyright (C) 2002-2017, and GNU GPL'd, by Julian Seward et al. >==76584== Using Valgrind-3.16.1 and LibVEX; rerun with -h for copyright info >==76584== Command: /home/lenaic/git/bin/git maintenance start >==76584== >==76584== >==76584== HEAP SUMMARY: >==76584== in use at exit: 34,880 bytes in 252 blocks >==76584== total heap usage: 820 allocs, 568 frees, 146,414 bytes allocated >==76584== >==76584== 65 bytes in 1 blocks are definitely lost in loss record 17 of 39 >==76584== at 0x483E6AF: malloc (vg_replace_malloc.c:306) >==76584== by 0x3DC39C: xrealloc (wrapper.c:126) >==76584== by 0x3992CC: strbuf_grow (strbuf.c:98) >==76584== by 0x39A473: strbuf_vaddf (strbuf.c:392) >==76584== by 0x39BC54: xstrvfmt (strbuf.c:979) >==76584== by 0x39BD2C: xstrfmt (strbuf.c:989) >==76584== by 0x18451B: update_background_schedule (gc.c:1977) >==76584== by 0x1846F6: maintenance_start (gc.c:2011) >==76584== by 0x1847B4: cmd_maintenance (gc.c:2030) >==76584== by 0x127A2E: run_builtin (git.c:453) >==76584== by 0x127E81: handle_builtin (git.c:704) >==76584== by 0x128142: run_argv (git.c:771) >==76584== >==76584== 240 bytes in 1 blocks are definitely lost in loss record 29 of 39 >==76584== at 0x4840D7B: realloc (vg_replace_malloc.c:834) >==76584== by 0x491CE5D: getdelim (in /usr/lib/libc-2.33.so) >==76584== by 0x39ADD7: strbuf_getwholeline (strbuf.c:635) >==76584== by 0x39AF31: strbuf_getdelim (strbuf.c:706) >==76584== by 0x39B064: strbuf_getline_lf (strbuf.c:727) >==76584== by 0x184273: crontab_update_schedule (gc.c:1919) >==76584== by 0x184678: update_background_schedule (gc.c:1997) >==76584== by 0x1846F6: maintenance_start (gc.c:2011) >==76584== by 0x1847B4: cmd_maintenance (gc.c:2030) >==76584== by 0x127A2E: run_builtin (git.c:453) >==76584== by 0x127E81: handle_builtin (git.c:704) >==76584== by 0x128142: run_argv (git.c:771) >==76584== >==76584== LEAK SUMMARY: >==76584== definitely lost: 305 bytes in 2 blocks >==76584== indirectly lost: 0 bytes in 0 blocks >==76584== possibly lost: 0 bytes in 0 blocks >==76584== still reachable: 34,575 bytes in 250 blocks >==76584== suppressed: 0 bytes in 0 blocks >==76584== Reachable blocks (those to which a pointer was found) are not shown. >==76584== To see them, rerun with: --leak-check=full --show-leak-kinds=all >==76584== >==76584== For lists of detected and suppressed errors, rerun with: -s >==76584== ERROR SUMMARY: 2 errors from 2 contexts (suppressed: 0 from 0) > >Signed-off-by: Lénaïc Huard <lenaic@lhuard.fr> >--- > builtin/gc.c | 2 ++ > 1 file changed, 2 insertions(+) > >diff --git a/builtin/gc.c b/builtin/gc.c >index ef7226d7bc..2574068ae2 100644 >--- a/builtin/gc.c >+++ b/builtin/gc.c >@@ -1947,6 +1947,7 @@ static int crontab_update_schedule(int run_maintenance, int fd, const char *cmd) > fprintf(cron_in, "\n%s\n", END_LINE); > } > >+ strbuf_release(&line); > fflush(cron_in); > fclose(cron_in); > close(crontab_edit.in); >@@ -1999,6 +2000,7 @@ static int update_background_schedule(int enable) > die("unknown background scheduler: %s", scheduler); > > rollback_lock_file(&lk); >+ free(lock_path); Based on your change, I think when "hold_lock_file_for_update()<0", we should also free local_path > free(testing); > return result; > } >-- >2.31.1 > > Thanks
next prev parent reply other threads:[~2021-05-10 6:39 UTC|newest] Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top 2021-05-09 22:16 Lénaïc Huard 2021-05-10 6:34 ` Junio C Hamano 2021-05-10 6:38 ` lilinchao [this message] 2021-05-10 7:11 ` Junio C Hamano [not found] ` <0c04f7c2b15f11eb82baa4badb2c2b1178978@pobox.com> 2021-05-10 7:50 ` lilinchao 2021-05-10 19:59 ` [PATCH v2 0/1] " Lénaïc Huard 2021-05-10 19:59 ` [PATCH v2 1/1] " Lénaïc Huard 2021-05-11 15:13 ` Derrick Stolee 2021-05-11 3:29 ` [PATCH v2 0/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 * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=67ed4ca6b15a11eba8d80024e87935e7@oschina.cn \ --to=lilinchao@oschina.cn \ --cc=dstolee@microsoft.com \ --cc=git@vger.kernel.org \ --cc=gitster@pobox.com \ --cc=lenaic@lhuard.fr \ --cc=sunshine@sunshineco.com \ --subject='Re: [PATCH] maintenance: fix two memory leaks' \ /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
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).