Message ID | pull.1820.git.1733515638.gitgitgadget@gmail.com (mailing list archive) |
---|---|
Headers | show |
Series | PATH WALK III: Add 'git backfill' command | expand |
It seems that the result of calling init_revisions() from backfill is leaked? https://github.com/git/git/actions/runs/12218430154/job/34083929479 I did not dig further but the below is from my local leaksanitizer run. Thanks. ================================================================= ==git==182342==ERROR: LeakSanitizer: detected memory leaks Direct leak of 576 byte(s) in 1 object(s) allocated from: #0 0x55d4b0e42915 in __interceptor_realloc (git+0x84915) (BuildId: c861e65ec43b0a3ef46b9555a81d6ddfc2358e8e) #1 0x55d4b119ce6d in xrealloc wrapper.c:140:8 #2 0x55d4b11204d4 in add_rev_cmdline revision.c:1563:2 #3 0x55d4b11187a1 in handle_revision_arg_1 revision.c:2263:2 #4 0x55d4b1118398 in handle_revision_arg revision.c:2275:12 #5 0x55d4b0e5233b in do_backfill builtin/backfill.c:100:2 #6 0x55d4b0e52253 in cmd_backfill builtin/backfill.c:146:9 #7 0x55d4b0e46b80 in run_builtin git.c:480:11 #8 0x55d4b0e45502 in handle_builtin git.c:741:9 #9 0x55d4b0e4649c in run_argv git.c:808:4 #10 0x55d4b0e45274 in cmd_main git.c:948:19 #11 0x55d4b0f6da8a in main common-main.c:9:11 #12 0x7ff25f97ac89 in __libc_start_call_main csu/../sysdeps/nptl/libc_start_call_main.h:58:16 #13 0x7ff25f97ad44 in __libc_start_main csu/../csu/libc-start.c:360:3 #14 0x55d4b0e171e0 in _start (git+0x591e0) (BuildId: c861e65ec43b0a3ef46b9555a81d6ddfc2358e8e) DEDUP_TOKEN: __interceptor_realloc--xrealloc--add_rev_cmdline--handle_revision_arg_1--handle_revision_arg--do_backfill--cmd_backfill--run_builtin--handle_builtin--run_argv--cmd_main--main--__libc_start_call_main--__libc_start_main--_start Indirect leak of 5 byte(s) in 1 object(s) allocated from: #0 0x55d4b0e424b6 in __interceptor_malloc (git+0x844b6) (BuildId: c861e65ec43b0a3ef46b9555a81d6ddfc2358e8e) #1 0x7ff25f9f34f9 in strdup string/strdup.c:42:15 #2 0x55d4b119cb14 in xstrdup wrapper.c:43:14 #3 0x55d4b1120506 in add_rev_cmdline revision.c:1565:23 #4 0x55d4b11187a1 in handle_revision_arg_1 revision.c:2263:2 #5 0x55d4b1118398 in handle_revision_arg revision.c:2275:12 #6 0x55d4b0e5233b in do_backfill builtin/backfill.c:100:2 #7 0x55d4b0e52253 in cmd_backfill builtin/backfill.c:146:9 #8 0x55d4b0e46b80 in run_builtin git.c:480:11 #9 0x55d4b0e45502 in handle_builtin git.c:741:9 #10 0x55d4b0e4649c in run_argv git.c:808:4 #11 0x55d4b0e45274 in cmd_main git.c:948:19 #12 0x55d4b0f6da8a in main common-main.c:9:11 #13 0x7ff25f97ac89 in __libc_start_call_main csu/../sysdeps/nptl/libc_start_call_main.h:58:16 #14 0x7ff25f97ad44 in __libc_start_main csu/../csu/libc-start.c:360:3 #15 0x55d4b0e171e0 in _start (git+0x591e0) (BuildId: c861e65ec43b0a3ef46b9555a81d6ddfc2358e8e) DEDUP_TOKEN: __interceptor_malloc--strdup--xstrdup--add_rev_cmdline--handle_revision_arg_1--handle_revision_arg--do_backfill--cmd_backfill--run_builtin--handle_builtin--run_argv--cmd_main--main--__libc_start_call_main--__libc_start_main--_start SUMMARY: LeakSanitizer: 581 byte(s) leaked in 2 allocation(s). Our logs revealed a memory leak... ++ rmdir /home/gitster/w/git.git/t/test-results/t5620-backfill.leak ++ : ++ exit 134 ++ eval_ret=134
Junio C Hamano <gitster@pobox.com> writes: > It seems that the result of calling init_revisions() from backfill > is leaked? > > https://github.com/git/git/actions/runs/12218430154/job/34083929479 > > I did not dig further but the below is from my local leaksanitizer > run. The attached patch seems to plug the leaks observed by your backfill tests. If you agree with the implementation of the change, you are welcome to squash it in. I may be missing a better mechanism in the path-walk API that I could use to plug the leaks, in which case, of course a fix using such a better mechanism is very much welcomed. A few things I noticed about path-walk API during my poking are: - struct path_walk_info has PATH_WALK_INFO_INIT() macro, but not a matching path_walk_info_init() helper function to help initialize any heap-allocated instances. In general, anything that requires _INIT() macro by definition wants to be initialized with more than nul-initialized (otherwise, it would be fine to leave it uninitialized in the BSS, clear with = {0} initialization on the stack), so lack of matching path_walk_info_init() raises an eyebrow. - struct path_walk_info seems to lack a destructor. In general, anything complex enough to require initializer should have one. - lack of destructor for path_walk_info requires users to release resources held by "struct pattern_list" instance at pwi.pl; if we had a destructor, we wouldn't have 2 of the three leaks we had to fix here. Thanks. diff --git c/builtin/backfill.c w/builtin/backfill.c index 225764f17e..1cf2df9303 100644 --- c/builtin/backfill.c +++ w/builtin/backfill.c @@ -92,8 +92,11 @@ static int do_backfill(struct backfill_context *ctx) if (ctx->sparse) { CALLOC_ARRAY(info.pl, 1); - if (get_sparse_checkout_patterns(info.pl)) + if (get_sparse_checkout_patterns(info.pl)) { + clear_pattern_list(info.pl); + free(info.pl); return error(_("problem loading sparse-checkout")); + } } repo_init_revisions(ctx->repo, &revs, ""); @@ -113,6 +116,11 @@ static int do_backfill(struct backfill_context *ctx) download_batch(ctx); clear_backfill_context(ctx); + release_revisions(&revs); + if (info.pl) { + clear_pattern_list(info.pl); + free(info.pl); + } return ret; }