From patchwork Wed Jul 13 13:10:30 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= X-Patchwork-Id: 12916668 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 6AE27C433EF for ; Wed, 13 Jul 2022 13:10:50 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235955AbiGMNKs (ORCPT ); Wed, 13 Jul 2022 09:10:48 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59822 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235819AbiGMNKo (ORCPT ); Wed, 13 Jul 2022 09:10:44 -0400 Received: from mail-wr1-x431.google.com (mail-wr1-x431.google.com [IPv6:2a00:1450:4864:20::431]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3797AE087 for ; Wed, 13 Jul 2022 06:10:43 -0700 (PDT) Received: by mail-wr1-x431.google.com with SMTP id v16so15412085wrd.13 for ; Wed, 13 Jul 2022 06:10:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=bY91G1xok4c6j7fQ4xDNpoYsnXh/337AQSkUoeMK/xs=; b=DfMJ/+0q4sKorYTk43/muRsL8YTO5MvXBlAeKsqwWg+QhPpcGA44u476lHi8fZqHpF 9/d9b4JbE+Ym+C1l+pl7J9GpAZI6xiYi0KhBK+i2GRTM6O0B/YyfGNrb4xZjf3Kct5RV vDKFaWsSkCHnuV3RkrFaxDLVNIhvWgBOuvmjoNwais63rlBAG6PT4VllwBsFCEfaXT7A OlrWzgF7PYx5rJNJ9w7U+1wGLlawIKF9PLp/3SlmpDJJeUsz4y08ONt8CWl8+0ypS4QZ 1mHfrulbtupTPrVrefzyxqNxCUbSSi06YuAtOtcF5WLhNyAynZnmtprHSfb/ba6WzVUm aALQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=bY91G1xok4c6j7fQ4xDNpoYsnXh/337AQSkUoeMK/xs=; b=VWaYTzT4jxDkMJMt8VwmgiXhLv5MxTK+WwLwmFxGjAS11b5JkZumLPNnV63b/1acm1 H9L90lVm1Z4ZYtj+hoS2jcDtRbfMYI/0k4Y8xgWN1h2RL4mRhEnnG7gEX8l+6v/52UaW Ums9SZPhM8kvOBQdYgI/AvE9DewSiOdm687vnQRNWRqPXZMCdDsDDTQStN0C+R85YkSp 4VwdcSYsW5I1kVzE5XSu56yEqzLIm7GN9CMbaBbrpxy9dQvL9aN++LcZ33E/iLYocUQD wu93RgXgjUMrrAWY42wSGIDkLB296aLiHUzTZBtVjHjHk6lIWictithz6TUCZKeyePlT ziow== X-Gm-Message-State: AJIora9y3xqszxAvzdUiPWJ7A2moJlB7vRuskm2SV4uADyLzn87a8KBd HtOirwAjpDHkdrJQhD1GYQ7bvkeQ2JgEpQ== X-Google-Smtp-Source: AGRyM1s8P+/7YQzXHXuhHh9oxzxJSM+Tex/7bQ6vJhkxkYxi+xXZ34Jk9V8zheDk4Gr9/iP8eYNa6g== X-Received: by 2002:a05:6000:1141:b0:21d:6ef3:e8c4 with SMTP id d1-20020a056000114100b0021d6ef3e8c4mr3365650wrx.573.1657717841462; Wed, 13 Jul 2022 06:10:41 -0700 (PDT) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id d15-20020a05600c34cf00b0039c4d022a44sm2183653wmq.1.2022.07.13.06.10.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 13 Jul 2022 06:10:40 -0700 (PDT) From: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= To: git@vger.kernel.org Cc: Junio C Hamano , Jeff King , =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= Subject: [PATCH 1/6] bisect.c: add missing "goto" for release_revisions() Date: Wed, 13 Jul 2022 15:10:30 +0200 Message-Id: X-Mailer: git-send-email 2.37.0.932.g7b7031e73bc In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org Add a missing "goto cleanup", this fixes a bug in f196c1e908d (revisions API users: use release_revisions() needing REV_INFO_INIT, 2022-04-13). Signed-off-by: Ævar Arnfjörð Bjarmason --- bisect.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bisect.c b/bisect.c index b63669cc9d7..421470bfa59 100644 --- a/bisect.c +++ b/bisect.c @@ -1054,7 +1054,7 @@ enum bisect_error bisect_next_all(struct repository *r, const char *prefix) */ res = error_if_skipped_commits(tried, NULL); if (res < 0) - return res; + goto cleanup; printf(_("%s was both %s and %s\n"), oid_to_hex(current_bad_oid), term_good, From patchwork Wed Jul 13 13:10:31 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= X-Patchwork-Id: 12916669 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id B664FC43334 for ; Wed, 13 Jul 2022 13:10:51 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236014AbiGMNKu (ORCPT ); Wed, 13 Jul 2022 09:10:50 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59848 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235845AbiGMNKp (ORCPT ); Wed, 13 Jul 2022 09:10:45 -0400 Received: from mail-wr1-x435.google.com (mail-wr1-x435.google.com [IPv6:2a00:1450:4864:20::435]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 69479BF61 for ; Wed, 13 Jul 2022 06:10:44 -0700 (PDT) Received: by mail-wr1-x435.google.com with SMTP id v16so15412156wrd.13 for ; Wed, 13 Jul 2022 06:10:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=SqaW0++fRWukVUKGvS3tyrR5kP/KTsmJWbZGYXwObO8=; b=jGIV1r7CHYgqV6/QPxY0lG7NrZs5OrhmPBjxAdGwtTo0q96+mgBtiArcPdNMlTcXt+ 51iKstIJk/LLYzkH0vwD/dVaQIaC7+Q38a82P2vBTlGa78rjYde9azSCSc2ksN3OxebQ Pd6t7GcsxTwgNa0nS55CyQuFrvaW+pHMJFKhvjQu2jA9l2A+9RMUl8UdNS762Q0ga93J D03z64LvM72uU5Y6UxiPV07LsrWRWCd4DOyknaEXbOLSa/2dHIUP6BQIibj89CJZgV20 pMKCW2UtKtgpc0nNkMkZVmba+pRGFy3H4261eudmBG4kaZpyKjdDA4uJeYeypcam++WJ d7mg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=SqaW0++fRWukVUKGvS3tyrR5kP/KTsmJWbZGYXwObO8=; b=39t+7QEzFJSQR4n3AiHfQh7pKyW5r3WgSFpgB/fbbKfoIJzkcq/8e+KnLDXu4aa4JZ 696geBJN1+ZR+wYZwxltDNuOy/72BQRNJqiTUxlqN6+vhNO9dAicLx3R0VFPF5Zkeehm aWlQRsxo8i9JwreJlaDPjLeBWZ5IRYbJJY9yiQXM3bzqLgDcK8/DQaWl8JypzXADhHBK 5n6AgpnBr2Qsc/nr47pASUkPrii0PsxvSkAlqNmExKNquLQ+JjwN1QgOX1LJO1UynDfQ sVu7fMEzcJWoouGivoiQDHlRM7hm6sM7DhiXazYtMMi5cOO10z6BhomV6PXfemKE4T/n 3vAg== X-Gm-Message-State: AJIora/Tazww3QqYyk7ThJ64lV+Ag/i+secd2x3zFk08DEJHcCuCNbCm 2hSEerH623egeXPaPeoqLhKnG3vKVLh8xA== X-Google-Smtp-Source: AGRyM1thVFP1dNKw17fBbLUlZo0HwwIxH30O8XO0xYSuE39Km+ZpVtXm8Iw8/5rgbKtsl7TbKO8Dmw== X-Received: by 2002:a05:6000:185:b0:21d:7ffc:4916 with SMTP id p5-20020a056000018500b0021d7ffc4916mr3281289wrx.692.1657717842692; Wed, 13 Jul 2022 06:10:42 -0700 (PDT) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id d15-20020a05600c34cf00b0039c4d022a44sm2183653wmq.1.2022.07.13.06.10.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 13 Jul 2022 06:10:41 -0700 (PDT) From: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= To: git@vger.kernel.org Cc: Junio C Hamano , Jeff King , =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= Subject: [PATCH 2/6] test-fast-rebase helper: use release_revisions() (again) Date: Wed, 13 Jul 2022 15:10:31 +0200 Message-Id: X-Mailer: git-send-email 2.37.0.932.g7b7031e73bc In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org Fix a bug in 0139c58ab95 (revisions API users: add "goto cleanup" for release_revisions(), 2022-04-13), in that commit a release_revisions() call was added to this function, but it never did anything due to this TODO memset() added in fe1a21d5267 (fast-rebase: demonstrate merge-ort's API via new test-tool command, 2020-10-29). Simply removing the memset() will fix the "cmdline" which can be seen when running t5520-pull.sh. This sort of thing could be detected automatically with a rule similar to the unused.cocci merged in 7fa60d2a5b6 (Merge branch 'ab/cocci-unused' into next, 2022-07-11). The following rule on top would catch the case being fixed here: @@ type T; identifier I; identifier REL1 =~ "^[a-z_]*_(release|reset|clear|free)$"; identifier REL2 =~ "^(release|clear|free)_[a-z_]*$"; @@ - memset(\( I \| &I \), 0, ...); ... when != \( I \| &I \) ( \( REL1 \| REL2 \)( \( I \| &I \), ...); | \( REL1 \| REL2 \)( \( &I \| I \) ); ) ... when != \( I \| &I \) That rule should arguably use only &I, not I (as we might be passed a pointer). He distinction would matter if anyone cared about the side-effects of a memset() followed by release() of a pointer to a variable passed into the function. As such a pattern would be at best very confusing, and most likely point to buggy code as in this case, the above rule is probably fine as-is. But as this rule only found one such bug in the entire codebase let's not add it to contrib/coccinelle/unused.cocci for now, we can always dig it up in the future if it's deemed useful. Signed-off-by: Ævar Arnfjörð Bjarmason --- t/helper/test-fast-rebase.c | 2 -- 1 file changed, 2 deletions(-) diff --git a/t/helper/test-fast-rebase.c b/t/helper/test-fast-rebase.c index 4e5553e2024..45665ec19a5 100644 --- a/t/helper/test-fast-rebase.c +++ b/t/helper/test-fast-rebase.c @@ -184,8 +184,6 @@ int cmd__fast_rebase(int argc, const char **argv) last_picked_commit = commit; last_commit = create_commit(result.tree, commit, last_commit); } - /* TODO: There should be some kind of rev_info_free(&revs) call... */ - memset(&revs, 0, sizeof(revs)); merge_switch_to_result(&merge_opt, head_tree, &result, 1, !result.clean); From patchwork Wed Jul 13 13:10:32 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= X-Patchwork-Id: 12916670 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 4147FC43334 for ; Wed, 13 Jul 2022 13:10:54 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236032AbiGMNKw (ORCPT ); Wed, 13 Jul 2022 09:10:52 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59804 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235040AbiGMNKr (ORCPT ); Wed, 13 Jul 2022 09:10:47 -0400 Received: from mail-wr1-x42c.google.com (mail-wr1-x42c.google.com [IPv6:2a00:1450:4864:20::42c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A8FBCC1B for ; Wed, 13 Jul 2022 06:10:45 -0700 (PDT) Received: by mail-wr1-x42c.google.com with SMTP id o4so15460249wrh.3 for ; Wed, 13 Jul 2022 06:10:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=gDN1UsTXBbc6niWwK2JHAx1ZOGrJxR72L51pB+BYc+4=; b=c4hIi0Ap1QVqJR0NPDao/HqTRVtUxCzZzxHhUrpOjnyu/T0Ie0FoCF0oC+c7DiJojm tYCwPnpVK9HTGFpizu7H4Gop7NAtS3w2Q0E3nPO0o4L4+CqXYZVUIsIrjFZrHMWZOPvn ZVb5UKtD6P0mw2pT54kVEhHteUJvVFYhPGcJbFEIKV4gIHs6K5O8Uiayxnco5TJOD/Ai xSBdM4qHBxezAifyeHxif/YF3HfNGMhf4+rNe/QZlN/uLbVQuPHjQl7dQFp8BXsDwZ/a Rw+j1jKn4ILZtyjLHYq/BhfWy/u+Zd7EdxvOmrTrrmj0ikuVSyn+knIZKFtyGSaOMqGU 8zkg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=gDN1UsTXBbc6niWwK2JHAx1ZOGrJxR72L51pB+BYc+4=; b=61cv2PuB2gwlTM4xtQyp4o1fEagDwfv2SyvjjSPZo1I8aYJAIqYhlxO+EbUjhNEITZ 1wmCxv3QWwQ2sv+GNbX+JM6tjaqQQf2MeV6f9GPUMvq0a/mMGqlmXLORQHF6tbhzVSHp JPhGRerJ8MAkuzOs8GoQz+wx96XGYAQ3FrLLT049/D0VIAHogRW15h0MN9iuF6c1h+mC 7fz8skM4aLu402L0wzBOkJTsnJIzqzSQS/tu7kBt7DCZQIPltOKRcs1rU0JeAtUlK4BC lxv4XI1Ut6jnyjMagqQbehzfENDEC2yEHKag+WXFc/6/4Jq3SpLbrzV7+uua/UhVhx4g boEA== X-Gm-Message-State: AJIora9eL11xcxYcdrla02r2gRhJCNK0g+kk4mmV5MgvJULp3hkVkhFo icGfgXKCVO/xNPSUf4cMqvTU32OO5t8HKw== X-Google-Smtp-Source: AGRyM1v4fu3/VhIZCgwb+n2EySn8DJHT78m4DxxoUpF70N20Y6CnQQsEz0NZ+Zkt4bvdqdU2ykJSKw== X-Received: by 2002:a5d:66c1:0:b0:21d:6c98:7aa4 with SMTP id k1-20020a5d66c1000000b0021d6c987aa4mr3173906wrw.136.1657717843913; Wed, 13 Jul 2022 06:10:43 -0700 (PDT) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id d15-20020a05600c34cf00b0039c4d022a44sm2183653wmq.1.2022.07.13.06.10.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 13 Jul 2022 06:10:42 -0700 (PDT) From: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= To: git@vger.kernel.org Cc: Junio C Hamano , Jeff King , =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= Subject: [PATCH 3/6] log: make the intent of cmd_show()'s "rev.pending" juggling clearer Date: Wed, 13 Jul 2022 15:10:32 +0200 Message-Id: X-Mailer: git-send-email 2.37.0.932.g7b7031e73bc In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org Adjust code added in 5d7eeee2ac6 (git-show: grok blobs, trees and tags, too, 2006-12-14) to use the "memcpy a &blank" idiom introduced in 5726a6b4012 (*.c *_init(): define in terms of corresponding *_INIT macro, 2021-07-01). Now the types in play are guaranteed to correspond, i.e. we used "int" here for the "count" before, but the corresponding "nr" is an "unsigned int". By using a "blank" object we almost entirely bypass that, we'll only need to declare our own "unsigned int i". There are no functional changes here aside from potential overflow guard rails, the structure only has these three members ("nr", "alloc" and "objects"), but now we're obviously future-proof against assuming that. Signed-off-by: Ævar Arnfjörð Bjarmason --- builtin/log.c | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/builtin/log.c b/builtin/log.c index 88a5e98875a..e0f40798d45 100644 --- a/builtin/log.c +++ b/builtin/log.c @@ -668,10 +668,12 @@ static void show_setup_revisions_tweak(struct rev_info *rev, int cmd_show(int argc, const char **argv, const char *prefix) { struct rev_info rev; - struct object_array_entry *objects; + struct object_array blank = OBJECT_ARRAY_INIT; + struct object_array cp = OBJECT_ARRAY_INIT; + unsigned int i; struct setup_revision_opt opt; struct pathspec match_all; - int i, count, ret = 0; + int ret = 0; init_log_defaults(); git_config(git_log_config, NULL); @@ -698,12 +700,11 @@ int cmd_show(int argc, const char **argv, const char *prefix) if (!rev.no_walk) return cmd_log_deinit(cmd_log_walk(&rev), &rev); - count = rev.pending.nr; - objects = rev.pending.objects; + memcpy(&cp, &rev.pending, sizeof(rev.pending)); rev.diffopt.no_free = 1; - for (i = 0; i < count && !ret; i++) { - struct object *o = objects[i].item; - const char *name = objects[i].name; + for (i = 0; i < cp.nr && !ret; i++) { + struct object *o = cp.objects[i].item; + const char *name = cp.objects[i].name; switch (o->type) { case OBJ_BLOB: ret = show_blob_object(&o->oid, &rev, name); @@ -726,7 +727,7 @@ int cmd_show(int argc, const char **argv, const char *prefix) if (!o) ret = error(_("could not read object %s"), oid_to_hex(oid)); - objects[i].item = o; + cp.objects[i].item = o; i--; break; } @@ -743,8 +744,7 @@ int cmd_show(int argc, const char **argv, const char *prefix) rev.shown_one = 1; break; case OBJ_COMMIT: - rev.pending.nr = rev.pending.alloc = 0; - rev.pending.objects = NULL; + memcpy(&rev.pending, &blank, sizeof(rev.pending)); add_object_array(o, name, &rev.pending); ret = cmd_log_walk_no_free(&rev); break; From patchwork Wed Jul 13 13:10:33 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= X-Patchwork-Id: 12916672 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id A6ADEC433EF for ; Wed, 13 Jul 2022 13:10:55 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236063AbiGMNKy (ORCPT ); Wed, 13 Jul 2022 09:10:54 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59802 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235930AbiGMNKr (ORCPT ); Wed, 13 Jul 2022 09:10:47 -0400 Received: from mail-wr1-x431.google.com (mail-wr1-x431.google.com [IPv6:2a00:1450:4864:20::431]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CDEDDD59 for ; Wed, 13 Jul 2022 06:10:45 -0700 (PDT) Received: by mail-wr1-x431.google.com with SMTP id v16so15412309wrd.13 for ; Wed, 13 Jul 2022 06:10:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=53NYxiy7JsQ4Nwv2ppG0ucODnzkND7IHCh4AsyJODHc=; b=aa/z5ZDlsG2fVNftBGhZ5YYoaytHPN36yy1I0LKZRFRDaeSw3wPczhJz71gzSSEZeR If8kbIbcJHSNHH+vzCeeR9f2skIiM2PEmh4o5Z5zgw0YjK9glO4Fs96p0d2RPs3LHClc YHDxi+pPag8t7in4JphNyTTqQS/kMWpSUT7wAjBtmhQfiy2e1vVtiSe59FPru7VTpwQK fFKWRh/FSLT9A8DeHIn8DUlVc+FAA4f+1zkdb6ypGnPEnrz0LB8vmZqRxOa0OkNp/z0T herY3Kv5wfWrXBPaX85jBrB3RgIss+vTlkVZglwS24v+dRNB6y3tR8WtvmhyAVM+0FhG Fd3g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=53NYxiy7JsQ4Nwv2ppG0ucODnzkND7IHCh4AsyJODHc=; b=LSfIGWCr7hBG9oEqD6/74IZ4KWSRSkZY402UCASgIqjOBCbinEKu2Aud5OWRHVEpFP EBuFFhaVQU2CQJH66FOrdI61dj/8o9SZEk3hNGWSWVThL+yweFi8ZpPj3nkruoLUWDWM BTquh99qa9H/z7cz+n3kHyhLounnk2nakFHal4h/X6obNKQj/DBmPtzBUkqKcOWc50yE XHnzAXvNqkqByMULlrpBAHTFQDEDDdWh5Qrl6igaoZBaSvuVcy9c1FloxKoySKZt23rB nhsGrwZ2Vm3sQ5WfOEoRZmcgrfcamLqXjG2iqYiJpDtAfOI8ycEqtqV9UB9LovcWV3Xb jmbA== X-Gm-Message-State: AJIora9oehUW8fPAnqIZjb9NezsbLgI1iJ7Wo7+0PAs1jwn4kyYy6KCS EqdrmygQ2sseiGzYRHL/T2FNcJy4vfCg/A== X-Google-Smtp-Source: AGRyM1sdVeKa8nismnbrlq79VFn7uAa3uBPWD8EsdDGkM64Cd1BZzaq07mN89pPke9VCBNYkJfbb1g== X-Received: by 2002:adf:e7cf:0:b0:21d:60e0:a71a with SMTP id e15-20020adfe7cf000000b0021d60e0a71amr3523550wrn.38.1657717845192; Wed, 13 Jul 2022 06:10:45 -0700 (PDT) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id d15-20020a05600c34cf00b0039c4d022a44sm2183653wmq.1.2022.07.13.06.10.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 13 Jul 2022 06:10:44 -0700 (PDT) From: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= To: git@vger.kernel.org Cc: Junio C Hamano , Jeff King , =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= Subject: [PATCH 4/6] log: fix common "rev.pending" memory leak in "git show" Date: Wed, 13 Jul 2022 15:10:33 +0200 Message-Id: X-Mailer: git-send-email 2.37.0.932.g7b7031e73bc In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org Fix a very common memory leak introduced in 5d7eeee2ac6 (git-show: grok blobs, trees and tags, too, 2006-12-14). When "git show" displays commits it needs to temporarily clobbers the "rev.pending" array, but by doing so we'll fail to release_revisions(), as we have for most other uses of "struct rev_info" since 2da81d1efb0 (Merge branch 'ab/plug-leak-in-revisions', 2022-06-07). In the preceding commit this code was made to use a more extendable pattern, which we can now complete. Once we've clobbered our "rev.pending" and invoked "cmd_log_walk_no_free()" we need to "object_array_clear()" our newly created "rev.pending" to avoid leaking the memory related to the one member array we've created. But more importantly we need to set "rev.pending" back to the original we squirreled away in the "cp" variable, so that we'll make use of the release_revisions() added in f6bfea0ad01 (revisions API users: use release_revisions() in builtin/log.c, 2022-04-13). In f6bfea0ad01 this memory leak was noted as an outstanding TODO, but it's now been fixed. Signed-off-by: Ævar Arnfjörð Bjarmason --- builtin/log.c | 2 ++ t/t0203-gettext-setlocale-sanity.sh | 1 + t/t1020-subdirectory.sh | 1 + t/t3307-notes-man.sh | 1 + t/t3920-crlf-messages.sh | 2 ++ t/t4069-remerge-diff.sh | 1 + t/t7007-show.sh | 1 + t/t7503-pre-commit-and-pre-merge-commit-hooks.sh | 1 + t/t9122-git-svn-author.sh | 1 - t/t9162-git-svn-dcommit-interactive.sh | 1 - 10 files changed, 10 insertions(+), 2 deletions(-) diff --git a/builtin/log.c b/builtin/log.c index e0f40798d45..77ec256a8ae 100644 --- a/builtin/log.c +++ b/builtin/log.c @@ -747,6 +747,8 @@ int cmd_show(int argc, const char **argv, const char *prefix) memcpy(&rev.pending, &blank, sizeof(rev.pending)); add_object_array(o, name, &rev.pending); ret = cmd_log_walk_no_free(&rev); + object_array_clear(&rev.pending); + memcpy(&rev.pending, &cp, sizeof(rev.pending)); break; default: ret = error(_("unknown type: %d"), o->type); diff --git a/t/t0203-gettext-setlocale-sanity.sh b/t/t0203-gettext-setlocale-sanity.sh index 0ce1f22eff6..86cff324ff1 100755 --- a/t/t0203-gettext-setlocale-sanity.sh +++ b/t/t0203-gettext-setlocale-sanity.sh @@ -5,6 +5,7 @@ test_description="The Git C functions aren't broken by setlocale(3)" +TEST_PASSES_SANITIZE_LEAK=true . ./lib-gettext.sh test_expect_success 'git show a ISO-8859-1 commit under C locale' ' diff --git a/t/t1020-subdirectory.sh b/t/t1020-subdirectory.sh index 9fdbb2af80e..45eef9457fe 100755 --- a/t/t1020-subdirectory.sh +++ b/t/t1020-subdirectory.sh @@ -6,6 +6,7 @@ test_description='Try various core-level commands in subdirectory. ' +TEST_PASSES_SANITIZE_LEAK=true . ./test-lib.sh . "$TEST_DIRECTORY"/lib-read-tree.sh diff --git a/t/t3307-notes-man.sh b/t/t3307-notes-man.sh index 1aa366a410e..ae316502c45 100755 --- a/t/t3307-notes-man.sh +++ b/t/t3307-notes-man.sh @@ -4,6 +4,7 @@ test_description='Examples from the git-notes man page Make sure the manual is not full of lies.' +TEST_PASSES_SANITIZE_LEAK=true . ./test-lib.sh test_expect_success 'setup' ' diff --git a/t/t3920-crlf-messages.sh b/t/t3920-crlf-messages.sh index 0276edbe3d3..4c661d4d54a 100755 --- a/t/t3920-crlf-messages.sh +++ b/t/t3920-crlf-messages.sh @@ -1,6 +1,8 @@ #!/bin/sh test_description='Test ref-filter and pretty APIs for commit and tag messages using CRLF' + +TEST_PASSES_SANITIZE_LEAK=true . ./test-lib.sh LIB_CRLF_BRANCHES="" diff --git a/t/t4069-remerge-diff.sh b/t/t4069-remerge-diff.sh index 35f94957fce..9e7cac68b1c 100755 --- a/t/t4069-remerge-diff.sh +++ b/t/t4069-remerge-diff.sh @@ -2,6 +2,7 @@ test_description='remerge-diff handling' +TEST_PASSES_SANITIZE_LEAK=true . ./test-lib.sh # This test is ort-specific diff --git a/t/t7007-show.sh b/t/t7007-show.sh index d6cc69e0f2c..f908a4d1abc 100755 --- a/t/t7007-show.sh +++ b/t/t7007-show.sh @@ -2,6 +2,7 @@ test_description='git show' +TEST_PASSES_SANITIZE_LEAK=true . ./test-lib.sh test_expect_success setup ' diff --git a/t/t7503-pre-commit-and-pre-merge-commit-hooks.sh b/t/t7503-pre-commit-and-pre-merge-commit-hooks.sh index ad1eb64ba0d..aa004b70a8d 100755 --- a/t/t7503-pre-commit-and-pre-merge-commit-hooks.sh +++ b/t/t7503-pre-commit-and-pre-merge-commit-hooks.sh @@ -5,6 +5,7 @@ test_description='pre-commit and pre-merge-commit hooks' GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME +TEST_PASSES_SANITIZE_LEAK=true . ./test-lib.sh test_expect_success 'root commit' ' diff --git a/t/t9122-git-svn-author.sh b/t/t9122-git-svn-author.sh index 527ba3d2932..0fc289ae0f0 100755 --- a/t/t9122-git-svn-author.sh +++ b/t/t9122-git-svn-author.sh @@ -2,7 +2,6 @@ test_description='git svn authorship' -TEST_FAILS_SANITIZE_LEAK=true . ./lib-git-svn.sh test_expect_success 'setup svn repository' ' diff --git a/t/t9162-git-svn-dcommit-interactive.sh b/t/t9162-git-svn-dcommit-interactive.sh index e2aa8ed88a9..b3ce033a0d3 100755 --- a/t/t9162-git-svn-dcommit-interactive.sh +++ b/t/t9162-git-svn-dcommit-interactive.sh @@ -4,7 +4,6 @@ test_description='git svn dcommit --interactive series' -TEST_FAILS_SANITIZE_LEAK=true . ./lib-git-svn.sh test_expect_success 'initialize repo' ' From patchwork Wed Jul 13 13:10:34 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= X-Patchwork-Id: 12916671 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id CB689C43334 for ; Wed, 13 Jul 2022 13:10:57 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236084AbiGMNK5 (ORCPT ); Wed, 13 Jul 2022 09:10:57 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60034 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235976AbiGMNKt (ORCPT ); Wed, 13 Jul 2022 09:10:49 -0400 Received: from mail-wm1-x336.google.com (mail-wm1-x336.google.com [IPv6:2a00:1450:4864:20::336]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D9EB4AE40 for ; Wed, 13 Jul 2022 06:10:47 -0700 (PDT) Received: by mail-wm1-x336.google.com with SMTP id ay25so6492737wmb.1 for ; Wed, 13 Jul 2022 06:10:47 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=4Hs+AZhfuVmwR939hq1q/v6gnBmzWfGPqsH5xKaQm3w=; b=h37BkOonlVWFnJ/yRtRlOzcujs3A6wJae0OUE7LkkZYEn9rj1ivJoIO1a4NBTTogD2 wLUZRWx0z02RiOYlLO+vooiIaE9scS7d6Ovl4FcHHxQj/fudbVpNCTMgkO9aI6gd9VeI vYAEaYxuZpEusaMSrGBxu5TJPCsMF1BBJnsF80ds9EvWACEEozCgI7H34INYSzFApZcf 0Phedu4ioRVgET9hfjVECJe5aRaYAdxbM4f9mBTxVniNRer2F97MwmZDnj6lzgVcYzL4 5NcASr04dESenUXXvrAPtDN5GCkhlNt+o77SuM9+aCbKUS6kxw7pNcyfUq+dzOTq5ynF DLgw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=4Hs+AZhfuVmwR939hq1q/v6gnBmzWfGPqsH5xKaQm3w=; b=IKzxRTIvlPVi4HFww3EkDQjoc/HB4i53xRT0iC9JacghJgxd06vVJdpFl2LEN2uHhU fgsYfjF981R1jvQNi8359wz0XpjWx8NApSslnHcJbIuPo9ZRSr2pjr4/Jg0flJJCU7cL gDVxxqBQsHEhQDOVLZnzGAByEQb4zYpdd32wUgKPxy1arFEUlJcFKA+6m8RYzUufUQE1 vjiVwPen7sajTpsIhrp9QRo3BpIUZ7zF5Dr6cX+dB08P77Xre2rOMgbU1B2oidmTBvhV 87n1JnlAcpd8kBvF8zOt5rqW2l9JCgsgh6oURdgqxX/khN3j495fwt9OQ+J8XQknMwiu BaVw== X-Gm-Message-State: AJIora9WrS4lxhjq+kn+8lx6fZmqW13YZyC6zpC5c1A1QARujdsAmGS3 nzpuPaiBOEIvl7sPDD1amzo1fx3BszIF6w== X-Google-Smtp-Source: AGRyM1uuA73fwLeelSPt2reWip+XfXYdJoosohuVumkGcj5OJcHo1g9mx7AW+4UiQZB+EmicLwX9OQ== X-Received: by 2002:a05:600c:211:b0:3a2:e982:1c12 with SMTP id 17-20020a05600c021100b003a2e9821c12mr9735712wmi.18.1657717846260; Wed, 13 Jul 2022 06:10:46 -0700 (PDT) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id d15-20020a05600c34cf00b0039c4d022a44sm2183653wmq.1.2022.07.13.06.10.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 13 Jul 2022 06:10:45 -0700 (PDT) From: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= To: git@vger.kernel.org Cc: Junio C Hamano , Jeff King , =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= Subject: [PATCH 5/6] bisect.c: partially fix bisect_rev_setup() memory leak Date: Wed, 13 Jul 2022 15:10:34 +0200 Message-Id: X-Mailer: git-send-email 2.37.0.932.g7b7031e73bc In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org Partially fix the memory leak noted in in 8a534b61241 (bisect: use argv_array API, 2011-09-13), which added the "XXX" comment seen in the context. We can partially fix it by having the bisect_rev_setup() function take a "struct strvec", rather than constructing it. As the comment notes we need to keep the construct "rev_argv" around while the "struct rev_info" is around, which as seen in the newly added "strvec_clear()" calls here we do after "release_revisions()". This "partially" fixes the memory leak because we're leaking the "--" added to the "rev_argv" here still, which will be addressed in a subsequent commit. Signed-off-by: Ævar Arnfjörð Bjarmason --- bisect.c | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/bisect.c b/bisect.c index 421470bfa59..6afb98be7a1 100644 --- a/bisect.c +++ b/bisect.c @@ -648,11 +648,11 @@ static struct commit_list *managed_skipped(struct commit_list *list, } static void bisect_rev_setup(struct repository *r, struct rev_info *revs, + struct strvec *rev_argv, const char *prefix, const char *bad_format, const char *good_format, int read_paths) { - struct strvec rev_argv = STRVEC_INIT; int i; repo_init_revisions(r, revs, prefix); @@ -660,16 +660,16 @@ static void bisect_rev_setup(struct repository *r, struct rev_info *revs, revs->commit_format = CMIT_FMT_UNSPECIFIED; /* rev_argv.argv[0] will be ignored by setup_revisions */ - strvec_push(&rev_argv, "bisect_rev_setup"); - strvec_pushf(&rev_argv, bad_format, oid_to_hex(current_bad_oid)); + strvec_push(rev_argv, "bisect_rev_setup"); + strvec_pushf(rev_argv, bad_format, oid_to_hex(current_bad_oid)); for (i = 0; i < good_revs.nr; i++) - strvec_pushf(&rev_argv, good_format, + strvec_pushf(rev_argv, good_format, oid_to_hex(good_revs.oid + i)); - strvec_push(&rev_argv, "--"); + strvec_push(rev_argv, "--"); if (read_paths) - read_bisect_paths(&rev_argv); + read_bisect_paths(rev_argv); - setup_revisions(rev_argv.nr, rev_argv.v, revs, NULL); + setup_revisions(rev_argv->nr, rev_argv->v, revs, NULL); /* XXX leak rev_argv, as "revs" may still be pointing to it */ } @@ -873,10 +873,11 @@ static enum bisect_error check_merge_bases(int rev_nr, struct commit **rev, int static int check_ancestors(struct repository *r, int rev_nr, struct commit **rev, const char *prefix) { + struct strvec rev_argv = STRVEC_INIT; struct rev_info revs; int res; - bisect_rev_setup(r, &revs, prefix, "^%s", "%s", 0); + bisect_rev_setup(r, &revs, &rev_argv, prefix, "^%s", "%s", 0); bisect_common(&revs); res = (revs.commits != NULL); @@ -885,6 +886,7 @@ static int check_ancestors(struct repository *r, int rev_nr, clear_commit_marks_many(rev_nr, rev, ALL_REV_FLAGS); release_revisions(&revs); + strvec_clear(&rev_argv); return res; } @@ -1010,6 +1012,7 @@ void read_bisect_terms(const char **read_bad, const char **read_good) */ enum bisect_error bisect_next_all(struct repository *r, const char *prefix) { + struct strvec rev_argv = STRVEC_INIT; struct rev_info revs = REV_INFO_INIT; struct commit_list *tried; int reaches = 0, all = 0, nr, steps; @@ -1037,7 +1040,7 @@ enum bisect_error bisect_next_all(struct repository *r, const char *prefix) if (res) goto cleanup; - bisect_rev_setup(r, &revs, prefix, "%s", "^%s", 1); + bisect_rev_setup(r, &revs, &rev_argv, prefix, "%s", "^%s", 1); revs.first_parent_only = !!(bisect_flags & FIND_BISECTION_FIRST_PARENT_ONLY); revs.limited = 1; @@ -1112,6 +1115,7 @@ enum bisect_error bisect_next_all(struct repository *r, const char *prefix) res = bisect_checkout(bisect_rev, no_checkout); cleanup: release_revisions(&revs); + strvec_clear(&rev_argv); return res; } From patchwork Wed Jul 13 13:10:35 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= X-Patchwork-Id: 12916673 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 64AB2C433EF for ; Wed, 13 Jul 2022 13:11:01 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236087AbiGMNK7 (ORCPT ); Wed, 13 Jul 2022 09:10:59 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60100 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236021AbiGMNKu (ORCPT ); Wed, 13 Jul 2022 09:10:50 -0400 Received: from mail-wr1-x42c.google.com (mail-wr1-x42c.google.com [IPv6:2a00:1450:4864:20::42c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2D80AC1B for ; Wed, 13 Jul 2022 06:10:48 -0700 (PDT) Received: by mail-wr1-x42c.google.com with SMTP id o4so15460486wrh.3 for ; Wed, 13 Jul 2022 06:10:48 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=gI835caINGX5JrD/1LW0PGVcj2NTdLr/tKFjIRcWZUo=; b=XoeS1JTGFndhF/HBf4Iw6hHWGFqfAU2cc5s9mmwp7eoD3QhT1uIaiS1I3mdxJVHHyo U1lGatGfWDPQHh818CGdkYQm9kPsCYtm5/XDSeAKqpAL0IqXkxcQI81KRFWRfa6pSOxM u8hD5Eg4KeI6fqYadTFzSKc40SCwhmlIOhZM0C71CIyooyeMMm66FFihqueNr96sacma scajyJ1yEi7dSozLjGDznnH27E3DaTOsBjhoACrg7ck9o0HqdFph+fAhpP/7AozEagpR S0ox3CM6P6q0ZMObbWVNJNRndNYa/QirPPtmyrR3kxAzCc04weMquVoCaFRQlvv79TMh /HWA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=gI835caINGX5JrD/1LW0PGVcj2NTdLr/tKFjIRcWZUo=; b=hwwSicUuU3YGf49bxvk5M2gatN/30wpCvTzll8O4ivzTpScdJGnDgYyWJTF6OhswWY 7/2FDBpCoRm1462HTlARL00Bc6OAS6fvY+HY5nlP0JJ/SgxbygLmUM10xHaiH7zdUXl5 vl++EZOpKi4P0ef3kHz2vtoqTXG90bkBgPNL0vXRBFhPBT20C4SFGluDkDpERoW4poMv nwh9+kwRroUyTAlvTsYMGaREsboajHxbI/n7bx18VJKE+ulm1sx47d5/aIpZZZXWd+ob ti526ArHVZhPAhpLkqQi+DGRld39NF7poqqPeYuRn9cXVzS+ZKgz4jhIsXznXK01XOdx afPA== X-Gm-Message-State: AJIora+LNpDMgXNh63Q3Z7tP8q8LBl8xieJQ3cGAQebn06iMNjy8Egli nUB1P/3BSudhNE0z1xCz7v080kXFSaQGCA== X-Google-Smtp-Source: AGRyM1tNkt9Lb/tQanGwZRFZ8mM+3yb5kT0oIxlZVrQTO1i+26F3UvDeiC3phUmye08+/V6vv/C47Q== X-Received: by 2002:a05:6000:144f:b0:21d:a3cc:a6fa with SMTP id v15-20020a056000144f00b0021da3cca6famr3256817wrx.191.1657717847505; Wed, 13 Jul 2022 06:10:47 -0700 (PDT) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id d15-20020a05600c34cf00b0039c4d022a44sm2183653wmq.1.2022.07.13.06.10.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 13 Jul 2022 06:10:46 -0700 (PDT) From: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= To: git@vger.kernel.org Cc: Junio C Hamano , Jeff King , =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= Subject: [PATCH 6/6] revisions API: don't leak memory on argv elements that need free()-ing Date: Wed, 13 Jul 2022 15:10:35 +0200 Message-Id: X-Mailer: git-send-email 2.37.0.932.g7b7031e73bc In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org Add a "free_removed_argv_elements" member to "struct setup_revision_opt", and use it to fix several memory leaks, e.g. the one with a "XXX" comment added in 8a534b61241 (bisect: use argv_array API, 2011-09-13). We have various memory leaks in APIs that take and munge "const char **argv", e.g. parse_options(). Sometimes these APIs are given the "argv" we get to the "main" function, in which case we don't leak memory, but other times we're giving it the "v" member of a "struct strvec" we created. There's several potential ways to fix those sort of leaks, we could add a "nodup" mode to "struct strvec", which would work for the cases where we push constant strings to it. But that wouldn't work as soon as we used strvec_pushf(), or otherwise needed to duplicate or create a string for that "struct strvec". Let's instead make it the responsibility of the revisions API. If it's going to clobber elements of argv it can also free() them, which it will now do if instructed to do so via "free_removed_argv_elements". Signed-off-by: Ævar Arnfjörð Bjarmason Signed-off-by: Ævar Arnfjörð Bjarmason Signed-off-by: Jeff King --- bisect.c | 6 ++++-- builtin/submodule--helper.c | 5 ++++- remote.c | 5 ++++- revision.c | 2 ++ revision.h | 3 ++- t/t2020-checkout-detach.sh | 1 + 6 files changed, 17 insertions(+), 5 deletions(-) diff --git a/bisect.c b/bisect.c index 6afb98be7a1..38b3891f3a6 100644 --- a/bisect.c +++ b/bisect.c @@ -653,6 +653,9 @@ static void bisect_rev_setup(struct repository *r, struct rev_info *revs, const char *bad_format, const char *good_format, int read_paths) { + struct setup_revision_opt opt = { + .free_removed_argv_elements = 1, + }; int i; repo_init_revisions(r, revs, prefix); @@ -669,8 +672,7 @@ static void bisect_rev_setup(struct repository *r, struct rev_info *revs, if (read_paths) read_bisect_paths(rev_argv); - setup_revisions(rev_argv->nr, rev_argv->v, revs, NULL); - /* XXX leak rev_argv, as "revs" may still be pointing to it */ + setup_revisions(rev_argv->nr, rev_argv->v, revs, &opt); } static void bisect_common(struct rev_info *revs) diff --git a/builtin/submodule--helper.c b/builtin/submodule--helper.c index c597df7528e..c4e47c1b15a 100644 --- a/builtin/submodule--helper.c +++ b/builtin/submodule--helper.c @@ -1114,6 +1114,9 @@ static int compute_summary_module_list(struct object_id *head_oid, { struct strvec diff_args = STRVEC_INIT; struct rev_info rev; + struct setup_revision_opt opt = { + .free_removed_argv_elements = 1, + }; struct module_cb_list list = MODULE_CB_LIST_INIT; int ret = 0; @@ -1131,7 +1134,7 @@ static int compute_summary_module_list(struct object_id *head_oid, init_revisions(&rev, info->prefix); rev.abbrev = 0; precompose_argv_prefix(diff_args.nr, diff_args.v, NULL); - setup_revisions(diff_args.nr, diff_args.v, &rev, NULL); + setup_revisions(diff_args.nr, diff_args.v, &rev, &opt); rev.diffopt.output_format = DIFF_FORMAT_NO_OUTPUT | DIFF_FORMAT_CALLBACK; rev.diffopt.format_callback = submodule_summary_callback; rev.diffopt.format_callback_data = &list; diff --git a/remote.c b/remote.c index b19e3a2f015..f05b50b1dd1 100644 --- a/remote.c +++ b/remote.c @@ -2169,6 +2169,9 @@ static int stat_branch_pair(const char *branch_name, const char *base, struct object_id oid; struct commit *ours, *theirs; struct rev_info revs; + struct setup_revision_opt opt = { + .free_removed_argv_elements = 1, + }; struct strvec argv = STRVEC_INIT; /* Cannot stat if what we used to build on no longer exists */ @@ -2203,7 +2206,7 @@ static int stat_branch_pair(const char *branch_name, const char *base, strvec_push(&argv, "--"); repo_init_revisions(the_repository, &revs, NULL); - setup_revisions(argv.nr, argv.v, &revs, NULL); + setup_revisions(argv.nr, argv.v, &revs, &opt); if (prepare_revision_walk(&revs)) die(_("revision walk setup failed")); diff --git a/revision.c b/revision.c index 211352795c5..3fa84247d33 100644 --- a/revision.c +++ b/revision.c @@ -2748,6 +2748,8 @@ int setup_revisions(int argc, const char **argv, struct rev_info *revs, struct s const char *arg = argv[i]; if (strcmp(arg, "--")) continue; + if (opt && opt->free_removed_argv_elements) + free((char *)argv[i]); argv[i] = NULL; argc = i; if (argv[i + 1]) diff --git a/revision.h b/revision.h index e576845cdd1..bb91e7ed914 100644 --- a/revision.h +++ b/revision.h @@ -375,7 +375,8 @@ struct setup_revision_opt { const char *def; void (*tweak)(struct rev_info *, struct setup_revision_opt *); unsigned int assume_dashdash:1, - allow_exclude_promisor_objects:1; + allow_exclude_promisor_objects:1, + free_removed_argv_elements:1; unsigned revarg_opt; }; int setup_revisions(int argc, const char **argv, struct rev_info *revs, diff --git a/t/t2020-checkout-detach.sh b/t/t2020-checkout-detach.sh index bc46713a43e..2eab6474f8d 100755 --- a/t/t2020-checkout-detach.sh +++ b/t/t2020-checkout-detach.sh @@ -4,6 +4,7 @@ test_description='checkout into detached HEAD state' GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME +TEST_PASSES_SANITIZE_LEAK=true . ./test-lib.sh check_detached () {