From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=202.12.124.157 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796139714; b=wDoHA3dfybUdXqEGExxv6G1EArSXazewRjx6cS3ATlNSdi6AlOTrmWLop0uao4L/+vY0 U2z3VaDH3FF2q8P3hOse0ZofSBbf9wtcBXa841KoqmWRNbZ4FLU1/qdUu2j4Amj4jDUL0 b/3HUdEQZ7zYrT9iFhcGhRsST+AUD90vwOOhh397r4Z5diKlXbIkU0oFdnYK5UBSMHZQx kWqeSgVH53VUR/oUd6H50MFWxFUZlTCCOHC26Yl1DY3LK2ghLF4Io45pyCbqW7BswUrIC tAfJsWlvs3oXePXxt7LA6yBt9hdEOaqSzFW5Cuknp5I745lnz7Si9OxNErxWNYL5UNQ== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796139714; h=DMARC-Filter:Received:Received:DKIM-Signature:DKIM-Signature: X-DKIM2-Info:DKIM2-Signature:X-DKIM2-Info:Message-Instance: X-ME-Sender:X-ME-Received:X-ME-Proxy-Cause:X-ME-Proxy:Feedback-ID: Received:Received:Date:From:To:Cc:Subject:Message-ID:References: MIME-Version:Content-Type:Content-Disposition: Content-Transfer-Encoding:In-Reply-To; bh=iZj41/aqRnp1NQEdG9NlzziLOoSK3zcIZbnpWsRuskk=; b=BL1wXk+d6dHzVMUhwkCsXi+XQHmi+6kJwT6/GTCsYI5DZ6aWQYss68FJqSVysXwC794A 7x4L0XcJQOHjHSZNc6Ua8yM7xIQprnSd/ykGD3KKGI2/CBhn5/tcofpUew0WWBet5ffOG lUjWwoFMt7HJRXPR3R/Q2pVPb2gmE2tDaZNLLsOWAvFnwcq5nn9UPqVXresUOPGpIjsKe aV6j1ZVMqomqz91VE5zW3u/+eii/tNeACVc0eafqxORs8ULHF8xLwLlDPDn6T9qwT4uND 6NTmhKQEGPUnvg1xeC9g+UsiCaX9C2E90Wb4Bdx306HjUxoPCYIgIFpPvV0IyGAnWsQ== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=pks.im; spf=pass smtp.mailfrom=pks.im; dkim=pass header.d=pks.im header.i=@pks.im header.a=rsa-sha256 header.s=fm3 header.b="VgDs/6Wy"; dkim=pass header.d=messagingengine.com header.i=@messagingengine.com header.a=rsa-sha256 header.s=fm3 header.b=BCGQo6Nz; arc=none smtp.remote-ip=202.12.124.157 Received: from fhigh-b6-smtp.messagingengine.com (fhigh-b6-smtp.messagingengine.com [202.12.124.157]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id A8B28606A31A for ; Tue, 1 Dec 2026 15:41:53 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org A8B28606A31A Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=pks.im Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=pks.im Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key, unprotected) header.d=pks.im header.i=@pks.im header.a=rsa-sha256 header.s=fm3 header.b=VgDs/6Wy; dkim=pass (2048-bit key, unprotected) header.d=messagingengine.com header.i=@messagingengine.com header.a=rsa-sha256 header.s=fm3 header.b=BCGQo6Nz Received: from phl-compute-11.internal (phl-compute-11.internal [10.202.2.51]) by mailfhigh.stl.internal (Postfix) with ESMTP id 113037A036B for ; Tue, 1 Dec 2026 10:41:53 -0500 (EST) Received: from phl-frontend-04 ([10.202.2.163]) by phl-compute-11.internal (MEProxy); Tue, 01 Dec 2026 10:41:53 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pks.im; h=cc:cc :content-transfer-encoding:content-type:content-type:date:date :from:from:in-reply-to:in-reply-to:message-id:mime-version :references:reply-to:subject:subject:to:to; s=fm3; t=1796139712; x=1796226112; bh=iZj41/aqRnp1NQEdG9NlzziLOoSK3zcIZbnpWsRuskk=; b= VgDs/6WyABUYnwbogI8jexHK3IGOiHiJyzcrg/H55kEtHFvdYOt+A4S52QLGovxl y1aFoTROYcJPtSXaQUv3T8jAJd/jDAT/HTDrkCIueI+KWz8yFtDzykNnsm5Kf5Gw +sqTUOI+jgdVYfXbeEGtPA8ySC/gxm0hAotTfx6Lvr27AchGUerRQH71VOhTkK4e W37XXqCbw6QyMrKmrfiDTwKCa4dHCjnx6ZiTh6/jFe4RNzaUyhODZlkJBHYi0HbF s3mw98bGd17GVTA6NvUQhqSdL2R30TcKLoT1Cj+dmYHKihrDJlf2pwMT7P0YtGfJ lzdSK4YK9mzFV8m6Gah/kQ== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-transfer-encoding :content-type:content-type:date:date:feedback-id:feedback-id :from:from:in-reply-to:in-reply-to:message-id:mime-version :references:reply-to:subject:subject:to:to:x-me-proxy :x-me-sender:x-me-sender:x-sasl-enc; s=fm3; t=1796139712; x= 1796226112; bh=iZj41/aqRnp1NQEdG9NlzziLOoSK3zcIZbnpWsRuskk=; b=B CGQo6Nzatv8qt+MMErszU6Q/7fJBKLslohDgnIWJI/wNNa2LpiSYb4keppcJwyQf xDMGUTDgL09fVgmI/aIE2WA//+fX7gwL6K4A28+f+VUFQTslXuTj00NOFIFEqocJ 5AefDiOOm2fUqvhqLhw+FUjxoUY6sINRNpvFaSzgtKZhmAgBsO7GuGIeAL3Pj1DL aW9FcIA2Yr6xJ6jA2gp9ZqV0sLoonC1eDJTZ8qxq5Mj7gOyvDQYfAR36g0C6xu0e FDMiTHsayAkVcJoYEGk/sFjspCgQKj9OzXC6/0nQr02yxDQZQDa5bASlveY4uFf/ GULKbhxwKAp8LPBR3q8hw== X-DKIM2-Info: draft=ietf-dkim-dkim2-spec-09; repo=github.com/dkim2wg/interop; date=2026-11-03; sw=lmtpprox; action=sign d=pks.im a=rsa-sha256; DKIM2-Signature: i=1; m=1; t=1796139712; d=pks.im; mf=PHBzQHBrcy5pbT4=; rt=PGdpdEB2Z2VyLmtlcm5lbC5vcmc+; s=fm3:rsa-sha256:uWVgCLEVFhDYVHdPN+ZykZlV1YZiXRASLs1nNfP6GJH7y0S lKlBrNvYF16rMHt4kV+7exuKCX/6nBmkcRBqAFprCuz5VBalRyuo20QgDd9bR2oJ 6pPNlTr7kON+vxMaTUToIThMw7VoN0RNZgYb/NpugGWKOyEmESxBrdDPo/0jwEoK fR38kWgajov/qsTerB4hd7uDEEaFWPJoKSNsbait/DSQoMQPbIw2JPJqSBzTrUoW f+0lwJ3Uzf1J+rghhXjHI90T7of5z0fihloQ94P3VF1bbdV3wfd1eoOC1s16hw0x 5MqwadztuRrFy2FyiQe0s6Wrs9X5DJ3+T3kFYIw==; X-DKIM2-Info: draft=ietf-dkim-dkim2-spec-09; repo=github.com/dkim2wg/interop; date=2026-11-03; sw=lmtpprox; action=mi-m=1; hc=13; hn=cc,content-disposition,content-transfer-encoding, content-type,date,feedback-id,from,in-reply-to,message-id, mime-version,references,subject,to; Message-Instance: m=1; h=sha256:uZBYa56LRSmwh9+H9cP+lc0bSVokfXVUW/4yeJ6YHmc=:MuJ8cR9Y80teMI6vKYUV9jXkBGqTcpkt+hZ6Ir7sSiY=; X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: dmFkZTG1KvOutcC6JbqoDQuyeEpe0WA+BYtOy+X5gjA8Xs4qwbgAKqTd3H7cd9wJ4spZZ1 aNrVF8dx+VJQ7FRBLVcu8cqFIjtov2c5oD+dw4yew9BAmouEEI0yKv35t6Nzk70hIiy7ws iNEmTtIX4I4O3ruQf5rJjgcOueNowk6b/b4Tljj8z3wAQQaUro54xcPI/+bBVnDdtveIhx uKdYHoHi7pEaAiV7ghNyqmCnoUXiFAcRNqUAKem37fk0znQkbncz+QBIbYx3wutOKPYsTR N1mJIeLYEovfcJzIoGUCZE46x9FskOYaN8I7F+WXbXbDn/v39K9PTeLI5Fvedwv1i+v7lZ rHOd/uNtzpX5Bz+51bfaJfTUPnGWGl4togNVekEoRE9mtvemE/SxmnqLT4o3VwdOiUg9Qv BJpVHeoEvgm6toKH23dT8BSZbc1DkjBdG27i1VWlHzWBg/sfFXbhp4JMcOLiQvLc/CZGo0 Jj9xSDDmyjR7Q/hwLMTlpvM0OUFr7fTzBCsrazO5XoweCN69KIZPQcxa894XhJvAwBM37q OSeRAl0b/GU7612yKNlCvBsUaW+s+ZG/ephsQv9u0pxm3OWch3MN4u5bQ7X4Q3k7EWY+9T S2eOGlroycN9spcIVSk+kkZ5NxWAiofpCtiDa8rBcRKNF3sx85yBaQ1v9UBQ X-ME-Proxy: Feedback-ID: i197146af:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Tue, 1 Dec 2026 10:41:51 -0500 (EST) Received: by mail (OpenSMTPD) with ESMTPSA id 5399df1e (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO); Tue, 1 Dec 2026 15:41:50 +0000 (UTC) Date: Tue, 1 Dec 2026 16:41:47 +0100 From: Patrick Steinhardt To: Onur =?utf-8?B?R8O8bmTDvHo=?= via GitGitGadget Cc: git@vger.kernel.org, Onur =?utf-8?B?R8O8bmTDvHo=?= Subject: Re: [PATCH] blame: free the suspects slab at scoreboard teardown Message-ID: References: X-Mailing-List: git@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: On Thu, Nov 26, 2026 at 03:37:10AM +0000, Onur Gündüz via GitGitGadget wrote: > From: =?UTF-8?q?Onur=20G=C3=BCnd=C3=BCz?= > > setup_scoreboard() initializes the file-static suspects slab each > time it runs, but cleanup_scoreboard() doesn't free the slab. A > second setup overwrites the pointer to the previous slab and leaks > its allocations. > > Clear the slab during cleanup. Each final blame entry holds a > reference to its origin, so release those references first: > blame_origin_decref() uses the slab to unlink an origin when its > reference count reaches zero. > > Add a regression test that sets up and cleans up two scoreboards > in one process. Without the fix, LeakSanitizer reports a leaked > slab; with the fix the test passes for both files and reftable. So this is a theoretical concern that cannot happen in practice because we never blame multiple times? Doesn't mean it's not worth fixing of course, also to help potential future users of this interface. > diff --git a/blame.c b/blame.c > index 126e232416..61e1a45650 100644 > --- a/blame.c > +++ b/blame.c > @@ -2935,6 +2935,7 @@ void setup_blame_bloom_data(struct blame_scoreboard *sb) > > void cleanup_scoreboard(struct blame_scoreboard *sb) > { > + clear_blame_suspects(&blame_suspects); > free(sb->lineno); > free(sb->final_buf); > clear_prio_queue(&sb->commits); It's of course quite ugly that we clean up global state in a function that pretends to act on a passed-in parameter. So ideally, we'd make the blame suspects a member of the scoreboard so that we can fix its lifecycle. But that may be a bigger change, and seeing the symmetry between `setup_scoreboard()` and `cleanup_scoreboard` makes me feel a bit more generous towards the change. > diff --git a/blame.h b/blame.h > index 3b34be0e5c..75a910bb67 100644 > --- a/blame.h > +++ b/blame.h > @@ -180,6 +180,7 @@ void init_scoreboard(struct blame_scoreboard *sb); > void setup_scoreboard(struct blame_scoreboard *sb, > struct blame_origin **orig); > void setup_blame_bloom_data(struct blame_scoreboard *sb); > +/* Release all entry and caller references to origins before clearing the slab. */ > void cleanup_scoreboard(struct blame_scoreboard *sb); I don't think this comment adds much. It might have made sense if it explicitly mentioned that we also release global state, but it doesn't. > diff --git a/builtin/blame.c b/builtin/blame.c > index 48d5251c6d..332795d18f 100644 > --- a/builtin/blame.c > +++ b/builtin/blame.c > @@ -1323,6 +1323,7 @@ parse_done: > cleanup: > for (ent = sb.ent; ent; ) { > struct blame_entry *e = ent->next; > + blame_origin_decref(ent->suspect); > free(ent); > ent = e; > } And I guess that these were previously held alive by the global blame suspects? > diff --git a/t/helper/test-repository.c b/t/helper/test-repository.c > index 9ba94cdffa..245253efbd 100644 > --- a/t/helper/test-repository.c > +++ b/t/helper/test-repository.c > @@ -65,11 +67,41 @@ static void test_get_commit_tree_in_graph(const char *gitdir, > repo_clear(&r); > } > > +static void test_blame_scoreboard(const char *path) > +{ > + struct repository *repo = the_repository; > + > + setup_git_directory(repo); > + /* A second setup exposes leaks left by the first scoreboard. */ > + for (int i = 0; i < 2; i++) { > + const char *args[] = { "blame", "HEAD", NULL }; > + struct blame_scoreboard sb; > + struct blame_origin *origin; > + struct rev_info revs; > + > + repo_init_revisions(repo, &revs, NULL); > + setup_revisions(ARRAY_SIZE(args) - 1, args, &revs, NULL); > + init_scoreboard(&sb); > + sb.repo = repo; > + sb.revs = &revs; > + sb.path = path; > + setup_scoreboard(&sb, &origin); > + blame_origin_decref(origin); > + cleanup_scoreboard(&sb); > + release_revisions(&revs); > + } > + repo_clear(repo); > +} > + > int cmd__repository(int argc, const char **argv) > { > if (argc < 2) > die("must have at least 2 arguments"); > - if (!strcmp(argv[1], "parse_commit_in_graph")) { > + if (!strcmp(argv[1], "blame-scoreboard")) { > + if (argc != 3) > + die("usage: test-tool repository blame-scoreboard "); > + test_blame_scoreboard(argv[2]); > + } else if (!strcmp(argv[1], "parse_commit_in_graph")) { > struct object_id oid; > if (argc < 5) > die("not enough arguments"); Instead of adding another helper, can this maybe be turned into a proper unit test? Hmm, it does require some test setup. But now that we have an in-memory object database I wonder whether we can abuse that for our tests and create a repository that sits purely in memory. It would of course also require an in-memory refdb, but that's probably not all that hard to do. In any case, if we had that, then writing unit tests for specific repository functionality that doesn't require a worktree may become more feasible. That being said, it feels a bit like a stretch for this particular commit, as that likely requires a bunch of work. But I feel like the boilerplate added here just to exercise a memory leak is way too excessive. So ultimately, if we cannot trigger this via normal plumbing commands, I'd lean towards not having tests at all. Thanks! Patrick