From patchwork Fri Dec 30 07:28:06 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: 13084144 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 2088FC4332F for ; Fri, 30 Dec 2022 07:28:31 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234641AbiL3H23 (ORCPT ); Fri, 30 Dec 2022 02:28:29 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51836 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234613AbiL3H2W (ORCPT ); Fri, 30 Dec 2022 02:28:22 -0500 Received: from mail-wm1-x331.google.com (mail-wm1-x331.google.com [IPv6:2a00:1450:4864:20::331]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id F3C9218B2F for ; Thu, 29 Dec 2022 23:28:20 -0800 (PST) Received: by mail-wm1-x331.google.com with SMTP id ja17so14658221wmb.3 for ; Thu, 29 Dec 2022 23:28:20 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=vEXsZGMKbnCOmMrqSxpq6j3rMj3iJt7KtJfq/5ZEi3s=; b=DrGBKfDga/UbjMpZdx7Eh50R5+ILvWouhFJmyaqg8IE9Q38wiFWca5fUfG1dUwPjvC 4gMZheNMYP37P6lugsjElpSmZqdVYpslYMSwXXh5vbNO4dhV7agQMouazNSpB4dnlbnp kV/2wUCAHDFL9RQtVLIgaPCEG/UN9t5CdTMxHIXTD2tt9jIPRCxzJEG/ajMpHZJlmmsN GGdYt12o07petMRssnVVKlx9JlXpH+OoH6QlMCmn65Yq6lwU3Ta2D+UPJWsvNjHTHuUD FwTTbRmlLD8VqmIaWWVduuH5nI/Ocf/tV7iVoZ/HwD7ICH1EMFhO9WugKWB0m7IEBHHy 6mfg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=vEXsZGMKbnCOmMrqSxpq6j3rMj3iJt7KtJfq/5ZEi3s=; b=1g03/PMiaY+CdDLST/ESHXzenNygeFvnHw1rvDkUXkC/S93B17wWEH+Vd2E3k8ZAip br5BHUwfCXnxQB5rmKqdKItXphBR94Qysyhwd/4INa4OpW+bbMWpEOBAAdtC69JqW3h1 THynCl0MY0PA7Uv7f/N2z9CF5vP6EauRYl3cm93x2PBPIt33Tm8aTgo++WN8+NEnAzB2 a1WED3WmhM5on6R2PpPxK9v+64CFC4crOdehZ5RHAYiDMDP13q3pM1dg8jQi9vHFyFoz yvg2xDSl9EhwhxZjnCn7Id8G37avCrWxbPcU1v1aovzrK9bZkmf//zfJMoBtY8hYo2Hg n+zQ== X-Gm-Message-State: AFqh2kqr/O3ZrdiN/BaAnyxjhQ1yTE2u0X0HtGIazQKdbBiBSzTcq3Pl qZ697mFLSTnYOd2MH9T6nJwB7JI1jxg77g== X-Google-Smtp-Source: AMrXdXuzwUga5KaVrJEJHaoOXRas39v7sUy66GCCh1cJDy6G6iciAp+mAofupr61yFHZYr46lEPeqw== X-Received: by 2002:a05:600c:4e51:b0:3cf:7b8b:6521 with SMTP id e17-20020a05600c4e5100b003cf7b8b6521mr21436519wmq.32.1672385299213; Thu, 29 Dec 2022 23:28:19 -0800 (PST) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id v13-20020a05600c444d00b003d998412db6sm6526449wmn.28.2022.12.29.23.28.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 29 Dec 2022 23:28:18 -0800 (PST) From: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= To: git@vger.kernel.org Cc: Phillip Wood , Johannes Schindelin , Junio C Hamano , Taylor Blau , =?utf-8?q?Ren=C3=A9_Scharfe?= , =?utf-8?b?w4Z2YXIgQXJuZmo=?= =?utf-8?b?w7Zyw7AgQmphcm1hc29u?= Subject: [PATCH 01/10] rebase: use "cleanup" pattern in do_interactive_rebase() Date: Fri, 30 Dec 2022 08:28:06 +0100 Message-Id: X-Mailer: git-send-email 2.39.0.1153.g589e4efe9dc In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org Use a "goto cleanup" pattern in do_interactive_rebase(). This eliminates some duplicated free() code added in 0609b741a43 (rebase -i: combine rebase--interactive.c with rebase.c, 2019-04-17), and sets us up for a subsequent commit which'll make further use of the "cleanup" label. Signed-off-by: Ævar Arnfjörð Bjarmason --- builtin/rebase.c | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/builtin/rebase.c b/builtin/rebase.c index 1481c5b6a5b..7141fd5e0c1 100644 --- a/builtin/rebase.c +++ b/builtin/rebase.c @@ -256,7 +256,7 @@ static void split_exec_commands(const char *cmd, struct string_list *commands) static int do_interactive_rebase(struct rebase_options *opts, unsigned flags) { - int ret; + int ret = -1; char *revisions = NULL, *shortrevisions = NULL; struct strvec make_script_args = STRVEC_INIT; struct todo_list todo_list = TODO_LIST_INIT; @@ -265,16 +265,12 @@ static int do_interactive_rebase(struct rebase_options *opts, unsigned flags) if (get_revision_ranges(opts->upstream, opts->onto, &opts->orig_head->object.oid, &revisions, &shortrevisions)) - return -1; + goto cleanup; if (init_basic_state(&replay, opts->head_name ? opts->head_name : "detached HEAD", - opts->onto, &opts->orig_head->object.oid)) { - free(revisions); - free(shortrevisions); - - return -1; - } + opts->onto, &opts->orig_head->object.oid)) + goto cleanup; if (!opts->upstream && opts->squash_onto) write_file(path_squash_onto(), "%s\n", @@ -304,6 +300,7 @@ static int do_interactive_rebase(struct rebase_options *opts, unsigned flags) opts->autosquash, opts->update_refs, &todo_list); } +cleanup: string_list_clear(&commands, 0); free(revisions); free(shortrevisions); From patchwork Fri Dec 30 07:28:07 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: 13084145 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 65AE7C46467 for ; Fri, 30 Dec 2022 07:28:32 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234643AbiL3H2a (ORCPT ); Fri, 30 Dec 2022 02:28:30 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51846 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234614AbiL3H2X (ORCPT ); Fri, 30 Dec 2022 02:28:23 -0500 Received: from mail-wm1-x330.google.com (mail-wm1-x330.google.com [IPv6:2a00:1450:4864:20::330]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0196E18B3B for ; Thu, 29 Dec 2022 23:28:22 -0800 (PST) Received: by mail-wm1-x330.google.com with SMTP id fm16-20020a05600c0c1000b003d96fb976efso12625127wmb.3 for ; Thu, 29 Dec 2022 23:28:21 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=gmusm75l7evrt7DWCX0ymYdvUs8/pyoIVbNR9v/f9P0=; b=Ruv3IriwGMicMatWnqR6YD0sSWXmJN8bOgjLl60mJxJToIsoHT0Rv/2sTfSqvsqDx1 uOVCeJS159zb1hWBgIWJBwp86Gh+pFD+j59SwlZvosKPAec480SW/sAa3fNV8Hy1K0of ZPyim62QBhS1dQWkOFHqN6nIiMgXGaIeZzQG8uSCp19yHHFS6Xgs4z0TKlVSMiH38Kin 259f0Id7p1BAI8/f4kYZHdVKZZE1TYT3utdwssWkG0WqfQPDw26W9lLGxjAsyrLKZN5U miy2zLIrpKtQBJR4PjPXwKRveMt52HmWGLipZxtTP7VV2G8B5z3iOS86u+mDY36qETsg 63CA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=gmusm75l7evrt7DWCX0ymYdvUs8/pyoIVbNR9v/f9P0=; b=VYGIlIK1sJ8f8EvCAI/NnizmD3OxJoC527UJTcPnIae4hVUwffL2k7E9oq8l2S07CG VYxGQsuArFgv307rgL91MfbdR6ksdbZPvzxf/l+WdxHwCFFsmZpLJlSGDvbvq4WrETwi lsOb092nnkMRE1gnllWbvd4nt+8lTY4V+5j5QqjQ6RvgdmfpnJChh9n1zVzNNSKwmvlS kBOaPiD/JrhARza8fEznZI8b8ww5nQWcdf6j7Zx1nYNkrjXZp5k9WC22ShkDc5N3omS6 7bgEz8K71BCby9zupgz3vJyaakkqn6j1piydevLHN/cLeUXEghxD9APbz/zh99CMdU08 MxPQ== X-Gm-Message-State: AFqh2ko5AmKFOG2Tu8lB/tMY8Viz1PPVc0mzDXcIQpcx72gmjmmPzH+h ow8NZitzCi+ZGCYYyXCt1H2I4NHcfZP61w== X-Google-Smtp-Source: AMrXdXsOoNmlnAtke/xi1T0oFGqte3ACrOwbTZAMbMQYzEOTiti/sUb4yr0zICZ/tnDJbRGs6r3UsA== X-Received: by 2002:a05:600c:4920:b0:3cf:7514:a82e with SMTP id f32-20020a05600c492000b003cf7514a82emr22301854wmp.23.1672385300099; Thu, 29 Dec 2022 23:28:20 -0800 (PST) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id v13-20020a05600c444d00b003d998412db6sm6526449wmn.28.2022.12.29.23.28.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 29 Dec 2022 23:28:19 -0800 (PST) From: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= To: git@vger.kernel.org Cc: Phillip Wood , Johannes Schindelin , Junio C Hamano , Taylor Blau , =?utf-8?q?Ren=C3=A9_Scharfe?= , =?utf-8?b?w4Z2YXIgQXJuZmo=?= =?utf-8?b?w7Zyw7AgQmphcm1hc29u?= Subject: [PATCH 02/10] sequencer.c: split up sequencer_remove_state() Date: Fri, 30 Dec 2022 08:28:07 +0100 Message-Id: X-Mailer: git-send-email 2.39.0.1153.g589e4efe9dc In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org Split off the free()-ing in sequencer_remove_state() into a utility function, which will be adjusted and called independent of the other code in sequencer_remove_state() in a subsequent commit. The only functional changes here are: * Changing the "int" to a "size_t", which is the correct type, as "xopts_nr" is a "size_t". * Calling the free() before the "if (is_rebase_i(opts) && ...)", which is OK, and makes a subsequent change smaller. Signed-off-by: Ævar Arnfjörð Bjarmason --- sequencer.c | 25 +++++++++++++++---------- 1 file changed, 15 insertions(+), 10 deletions(-) diff --git a/sequencer.c b/sequencer.c index bcb662e23be..655ae9f1a72 100644 --- a/sequencer.c +++ b/sequencer.c @@ -351,10 +351,24 @@ static const char *gpg_sign_opt_quoted(struct replay_opts *opts) return buf.buf; } +static void replay_opts_release(struct replay_opts *opts) +{ + free(opts->gpg_sign); + free(opts->reflog_action); + free(opts->default_strategy); + free(opts->strategy); + for (size_t i = 0; i < opts->xopts_nr; i++) + free(opts->xopts[i]); + free(opts->xopts); + strbuf_release(&opts->current_fixups); +} + int sequencer_remove_state(struct replay_opts *opts) { struct strbuf buf = STRBUF_INIT; - int i, ret = 0; + int ret = 0; + + replay_opts_release(opts); if (is_rebase_i(opts) && strbuf_read_file(&buf, rebase_path_refs_to_delete(), 0) > 0) { @@ -373,15 +387,6 @@ int sequencer_remove_state(struct replay_opts *opts) } } - free(opts->gpg_sign); - free(opts->reflog_action); - free(opts->default_strategy); - free(opts->strategy); - for (i = 0; i < opts->xopts_nr; i++) - free(opts->xopts[i]); - free(opts->xopts); - strbuf_release(&opts->current_fixups); - strbuf_reset(&buf); strbuf_addstr(&buf, get_dir(opts)); if (remove_dir_recursively(&buf, 0)) From patchwork Fri Dec 30 07:28:08 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: 13084146 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 69DB8C4332F for ; Fri, 30 Dec 2022 07:28:35 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234645AbiL3H2c (ORCPT ); Fri, 30 Dec 2022 02:28:32 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51852 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234619AbiL3H2Y (ORCPT ); Fri, 30 Dec 2022 02:28:24 -0500 Received: from mail-wm1-x32b.google.com (mail-wm1-x32b.google.com [IPv6:2a00:1450:4864:20::32b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id F03F818E08 for ; Thu, 29 Dec 2022 23:28:22 -0800 (PST) Received: by mail-wm1-x32b.google.com with SMTP id bg13-20020a05600c3c8d00b003d9712b29d2so12261408wmb.2 for ; Thu, 29 Dec 2022 23:28:22 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=Nqa2DMjXohc5ZdGF/5POLR4SSHEAn6SS3Cw+rLCKpaA=; b=SWVxmMEJEojar1AWLTWfbMUL+nTX9kSNC6MEFayrEJFB3SOvi5YHOMxYqc35QwrH7a KqlmNj193xo5oUOwC/r8Q4WHTb3NOP6pQDxM/OZp2TbggM2y/bRxDYLCQFS6c+aa3B4r OQjiJAdiVuT86toZrs4kxXYWWKPUoHrLeyq2xIU88f4ObFBAr8cvAZKsRgVP0YB3FyJn yC6vaxwtBJmx3CYjN8uIo2TYJQ5rk01YRrLXvzVh5Vo7z6OxEMpOcEJR88WDqJqY402y czKfaIdbxRDU/a1k1wmvDzFkDwT/kEaYpCTu8N5Fz+PW6iSX4cpbLyde8FzytDxN1N4H qufA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=Nqa2DMjXohc5ZdGF/5POLR4SSHEAn6SS3Cw+rLCKpaA=; b=JY9g9qq18G5IFELhGIvuWhN9M52jGkvbEj8Qp4LdIUoQKc9XE7loHK0rrKVicDDZOg dYmMIW73MLexTCwiO3YPtxYqxfHvVnf1307s466IMRCy10FqteLawmk2wOLy13ePI8wv BvZr7MpNcfAVzBEhDmgtflGJWz9khf5nehXgH1X7qqIDhVlADMwEO+QalpqcFlO3bv++ pFcVFalHdyKLVOeflVyjqVhejXZbdUUuQRj4Ky1aCW9nIt4rST/TyNpvT2gmOoFsroTu Bkty9MkcgUp+tuBXIraPDeUQzSOBGBMNlx4CSfZo1FhCsr3t+sDjvXpaPBeCHFv2fWdI 5RRA== X-Gm-Message-State: AFqh2ko/+kMfD7+yK7nxj04/4Ck1cDuTN2EJ+HwqQV/xtdLAxeGkcpzb 5XQ6hVvBTayVQzJiBVe5qt3OPQyMRvy/Fw== X-Google-Smtp-Source: AMrXdXvVvREsgd6AfdzHeo5GbYcAEhsoO1wH1b8yKDtyvjt5uLZbyyqs19dyNN0bfAFF50Z+3XSPyQ== X-Received: by 2002:a05:600c:3596:b0:3cf:497c:c4f5 with SMTP id p22-20020a05600c359600b003cf497cc4f5mr22866168wmq.13.1672385301110; Thu, 29 Dec 2022 23:28:21 -0800 (PST) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id v13-20020a05600c444d00b003d998412db6sm6526449wmn.28.2022.12.29.23.28.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 29 Dec 2022 23:28:20 -0800 (PST) From: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= To: git@vger.kernel.org Cc: Phillip Wood , Johannes Schindelin , Junio C Hamano , Taylor Blau , =?utf-8?q?Ren=C3=A9_Scharfe?= , =?utf-8?b?w4Z2YXIgQXJuZmo=?= =?utf-8?b?w7Zyw7AgQmphcm1hc29u?= Subject: [PATCH 03/10] rebase & sequencer API: fix get_replay_opts() leak in "rebase" Date: Fri, 30 Dec 2022 08:28:08 +0100 Message-Id: X-Mailer: git-send-email 2.39.0.1153.g589e4efe9dc In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org Make the recently added replay_opts_release() function non-static and use it for freeing the "struct replay_opts" constructed by the get_replay_opts() function in "builtin/rebase.c". See [1] for the initial addition of get_replay_opts(). To safely call our new replay_opts_release() we'll need to change all the free() to a FREE_AND_NULL(), and set "xopts_nr" to "0" after we loop over it and free() it (the free() in the loop doesn't need to be a FREE_AND_NULL()). This is because in e.g. do_interactive_rebase() we construct a "struct replay_opts" with "get_replay_opts()", and then call "complete_action()". If we get far enough in that function without encountering errors we'll call "pick_commits()" which (indirectly) calls sequencer_remove_state() at the end. But if we encounter errors anywhere along the way we'd punt out early, and not free() the memory we allocated. Remembering whether we previously called sequencer_remove_state() would be a hassle, so let's make it safe to re-invoke replay_opts_release() instead. I experimented with a change to be more paranoid instead, i.e. to exhaustively check our state via an enum. We could make sure that we: - Only allow calling "replay_opts_release()" after "sequencer_remove_state()", but not the other way around. - Forbid invoking either function twice in a row. But such paranoia isn't warranted here, let's instead take the easy way out and FREE_AND_NULL() this. See [2] for the initial implementation of "sequencer_remove_state()", which assumed that it should be removing the full (including on-disk) rebase state as a one-off. 1. 73fdc535d26 (rebase -i: use struct rebase_options to parse args, 2019-04-17) 2. 26ae337be11 (revert: Introduce --reset to remove sequencer state, 2011-08-04) Signed-off-by: Ævar Arnfjörð Bjarmason --- Re the "I experimented with...", the earlier version can be seen at https://github.com/avar/git/commit/7a150d1b7e2; It's the commit I linked to from https://lore.kernel.org/git/221108.864jv9sc9r.gmgdl@evledraar.gmail.com/ (which is mentioned in the CL). builtin/rebase.c | 2 ++ sequencer.c | 13 +++++++------ sequencer.h | 1 + t/t3405-rebase-malformed.sh | 1 + t/t3412-rebase-root.sh | 1 + t/t3423-rebase-reword.sh | 1 + t/t3437-rebase-fixup-options.sh | 1 + t/t3438-rebase-broken-files.sh | 2 ++ t/t7402-submodule-rebase.sh | 1 + t/t9106-git-svn-commit-diff-clobber.sh | 1 - t/t9164-git-svn-dcommit-concurrent.sh | 1 - 11 files changed, 17 insertions(+), 8 deletions(-) diff --git a/builtin/rebase.c b/builtin/rebase.c index 7141fd5e0c1..91bf55be6e6 100644 --- a/builtin/rebase.c +++ b/builtin/rebase.c @@ -301,6 +301,7 @@ static int do_interactive_rebase(struct rebase_options *opts, unsigned flags) } cleanup: + replay_opts_release(&replay); string_list_clear(&commands, 0); free(revisions); free(shortrevisions); @@ -343,6 +344,7 @@ static int run_sequencer_rebase(struct rebase_options *opts) struct replay_opts replay_opts = get_replay_opts(opts); ret = sequencer_continue(the_repository, &replay_opts); + replay_opts_release(&replay_opts); break; } case ACTION_EDIT_TODO: diff --git a/sequencer.c b/sequencer.c index 655ae9f1a72..e29a97b6caa 100644 --- a/sequencer.c +++ b/sequencer.c @@ -351,15 +351,16 @@ static const char *gpg_sign_opt_quoted(struct replay_opts *opts) return buf.buf; } -static void replay_opts_release(struct replay_opts *opts) +void replay_opts_release(struct replay_opts *opts) { - free(opts->gpg_sign); - free(opts->reflog_action); - free(opts->default_strategy); - free(opts->strategy); + FREE_AND_NULL(opts->gpg_sign); + FREE_AND_NULL(opts->reflog_action); + FREE_AND_NULL(opts->default_strategy); + FREE_AND_NULL(opts->strategy); for (size_t i = 0; i < opts->xopts_nr; i++) free(opts->xopts[i]); - free(opts->xopts); + opts->xopts_nr = 0; + FREE_AND_NULL(opts->xopts); strbuf_release(&opts->current_fixups); } diff --git a/sequencer.h b/sequencer.h index 888c18aad71..3bcdfa1b586 100644 --- a/sequencer.h +++ b/sequencer.h @@ -158,6 +158,7 @@ int sequencer_pick_revisions(struct repository *repo, int sequencer_continue(struct repository *repo, struct replay_opts *opts); int sequencer_rollback(struct repository *repo, struct replay_opts *opts); int sequencer_skip(struct repository *repo, struct replay_opts *opts); +void replay_opts_release(struct replay_opts *opts); int sequencer_remove_state(struct replay_opts *opts); #define TODO_LIST_KEEP_EMPTY (1U << 0) diff --git a/t/t3405-rebase-malformed.sh b/t/t3405-rebase-malformed.sh index 25243318618..8979bc34073 100755 --- a/t/t3405-rebase-malformed.sh +++ b/t/t3405-rebase-malformed.sh @@ -5,6 +5,7 @@ test_description='rebase should handle arbitrary git message' GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME +TEST_PASSES_SANITIZE_LEAK=true . ./test-lib.sh . "$TEST_DIRECTORY"/lib-rebase.sh diff --git a/t/t3412-rebase-root.sh b/t/t3412-rebase-root.sh index 58371d8a547..e75b3d0e07c 100755 --- a/t/t3412-rebase-root.sh +++ b/t/t3412-rebase-root.sh @@ -7,6 +7,7 @@ Tests if git rebase --root --onto can rebase the root commit. GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME +TEST_PASSES_SANITIZE_LEAK=true . ./test-lib.sh log_with_names () { diff --git a/t/t3423-rebase-reword.sh b/t/t3423-rebase-reword.sh index 4859bb8f722..2fab703d615 100755 --- a/t/t3423-rebase-reword.sh +++ b/t/t3423-rebase-reword.sh @@ -2,6 +2,7 @@ test_description='git rebase interactive with rewording' +TEST_PASSES_SANITIZE_LEAK=true . ./test-lib.sh . "$TEST_DIRECTORY"/lib-rebase.sh diff --git a/t/t3437-rebase-fixup-options.sh b/t/t3437-rebase-fixup-options.sh index c023fefd681..274699dadb8 100755 --- a/t/t3437-rebase-fixup-options.sh +++ b/t/t3437-rebase-fixup-options.sh @@ -14,6 +14,7 @@ to the "fixup" command that works with "fixup!", "fixup -C" works with "amend!" upon --autosquash. ' +TEST_PASSES_SANITIZE_LEAK=true . ./test-lib.sh . "$TEST_DIRECTORY"/lib-rebase.sh diff --git a/t/t3438-rebase-broken-files.sh b/t/t3438-rebase-broken-files.sh index b92a3ce46b8..c614c4f2e4b 100755 --- a/t/t3438-rebase-broken-files.sh +++ b/t/t3438-rebase-broken-files.sh @@ -1,6 +1,8 @@ #!/bin/sh test_description='rebase behavior when on-disk files are broken' + +TEST_PASSES_SANITIZE_LEAK=true . ./test-lib.sh test_expect_success 'set up conflicting branches' ' diff --git a/t/t7402-submodule-rebase.sh b/t/t7402-submodule-rebase.sh index ebeca12a711..b19792b3269 100755 --- a/t/t7402-submodule-rebase.sh +++ b/t/t7402-submodule-rebase.sh @@ -5,6 +5,7 @@ test_description='Test rebasing, stashing, etc. with submodules' +TEST_PASSES_SANITIZE_LEAK=true . ./test-lib.sh test_expect_success setup ' diff --git a/t/t9106-git-svn-commit-diff-clobber.sh b/t/t9106-git-svn-commit-diff-clobber.sh index 3cab0b9720a..bca496c40e0 100755 --- a/t/t9106-git-svn-commit-diff-clobber.sh +++ b/t/t9106-git-svn-commit-diff-clobber.sh @@ -3,7 +3,6 @@ # Copyright (c) 2006 Eric Wong test_description='git svn commit-diff clobber' -TEST_FAILS_SANITIZE_LEAK=true . ./lib-git-svn.sh test_expect_success 'initialize repo' ' diff --git a/t/t9164-git-svn-dcommit-concurrent.sh b/t/t9164-git-svn-dcommit-concurrent.sh index 1465156072e..c8e6c0733f4 100755 --- a/t/t9164-git-svn-dcommit-concurrent.sh +++ b/t/t9164-git-svn-dcommit-concurrent.sh @@ -5,7 +5,6 @@ test_description='concurrent git svn dcommit' -TEST_FAILS_SANITIZE_LEAK=true . ./lib-git-svn.sh From patchwork Fri Dec 30 07:28:09 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: 13084147 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 89B3AC4332F for ; Fri, 30 Dec 2022 07:28:40 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234653AbiL3H2h (ORCPT ); Fri, 30 Dec 2022 02:28:37 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51846 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234621AbiL3H2Z (ORCPT ); Fri, 30 Dec 2022 02:28:25 -0500 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 16C2A18B2F for ; Thu, 29 Dec 2022 23:28:24 -0800 (PST) Received: by mail-wm1-x336.google.com with SMTP id m8-20020a05600c3b0800b003d96f801c48so12460896wms.0 for ; Thu, 29 Dec 2022 23:28:24 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=vMJbdfDAUOntlmO+Tipo3vpuLC2gDe5+Ru/8sKKhi5w=; b=Tj/KgbSCFQgrJ0FG3cZhR9jy8DL8XZ/tlWb+76Vp1IJ9UCRY+ul6o+p1E1RqUP5ofO U9EpRhMPs3M7y8ZzoonmqFyCWLnysroH0f31w42gADwnYYCdX8KAvYh5BZyqZOjC1ae4 7mQChD6fRsXCE/OYnWFuK9uoQq7CkHjtgekLAH6WEiE3SId4N0sSY6aYmrX1+fJ6EDh3 MkVdfc9lz2X4k3++cztY/ekpSEmrGBnQ7lLK/+D+8hL1I0p2k2BbKbPdwIHaQ5q9kvGL AEURTTHlotuyIzUj29jUB79Bj6QW+tjYgRrSxJSyPEEEkH44jgrixXDksw/mn8XtA0aC e0qg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=vMJbdfDAUOntlmO+Tipo3vpuLC2gDe5+Ru/8sKKhi5w=; b=1B1OA8wUBVSF0a9Ldz0m8AmHsQSHl3N7Xa1qDXlRm5LhN1JhOUWkN3nmqZ295HbUp3 pHYPF7Qg/Qh5T+qzmJnr73nYU6RSzrR97kDjDRYT/cqLuxesetmOZzxW2TazaPpSaqov AaeXrhkPN1KlC/QLNXqrb1LWMsJYi9AvNgY5xbKzezFiax24fLJua/l+UHARJErTiOQ7 VT0+MSht1EUdkS24P1MFpIWEBaR5kpp98SKr6YdoEPyDh0/leB7NK6MgrVPvJGCz8YO8 QZa4hZ1oMbDcJEUnm0iixyVVBkP0tZdzy5x36TK/zg/zvnvTch19Uioi6PtZN7qu5fRl RyIw== X-Gm-Message-State: AFqh2kqwqoNuOckmznH7CXmY9G1f80j0G90vL//hGDbKV2giwn30+7uW UZPa7NzLx8fzGFvgWQGz9I4YwkcxmF4IpQ== X-Google-Smtp-Source: AMrXdXvQQbLVWGJPf+nwA0SC9HibnGWk7TQzuNOiLElWYAzhqNXC92HgUMRe1Zeopy7yTP/7CQrCKg== X-Received: by 2002:a05:600c:3c8c:b0:3d9:719b:bd1b with SMTP id bg12-20020a05600c3c8c00b003d9719bbd1bmr19900819wmb.33.1672385302164; Thu, 29 Dec 2022 23:28:22 -0800 (PST) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id v13-20020a05600c444d00b003d998412db6sm6526449wmn.28.2022.12.29.23.28.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 29 Dec 2022 23:28:21 -0800 (PST) From: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= To: git@vger.kernel.org Cc: Phillip Wood , Johannes Schindelin , Junio C Hamano , Taylor Blau , =?utf-8?q?Ren=C3=A9_Scharfe?= , =?utf-8?b?w4Z2YXIgQXJuZmo=?= =?utf-8?b?w7Zyw7AgQmphcm1hc29u?= Subject: [PATCH 04/10] builtin/revert.c: refactor run_sequencer() return pattern Date: Fri, 30 Dec 2022 08:28:09 +0100 Message-Id: X-Mailer: git-send-email 2.39.0.1153.g589e4efe9dc In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org Refactor the return pattern in run_sequencer() to make it easier to insert a "replay_opts_release()" call between the "fn(...)" invocation and the eventual return. Usually we'd name the "cbfun" here "fn", but by using this name we'll nicely align all the "cmd == ?" comparisons. Signed-off-by: Ævar Arnfjörð Bjarmason --- builtin/revert.c | 31 ++++++++++++++++++------------- 1 file changed, 18 insertions(+), 13 deletions(-) diff --git a/builtin/revert.c b/builtin/revert.c index f2d86d2a8f9..e956d125a2b 100644 --- a/builtin/revert.c +++ b/builtin/revert.c @@ -93,6 +93,15 @@ static void verify_opt_compatible(const char *me, const char *base_opt, ...) die(_("%s: %s cannot be used with %s"), me, this_opt, base_opt); } +static int sequencer_remove_branch_state(struct repository *r, + struct replay_opts *opts) +{ + int ret = sequencer_remove_state(opts); + if (!ret) + remove_branch_state(the_repository, 0); + return ret; +} + static int run_sequencer(int argc, const char **argv, struct replay_opts *opts) { const char * const * usage_str = revert_or_cherry_pick_usage(opts); @@ -120,6 +129,8 @@ static int run_sequencer(int argc, const char **argv, struct replay_opts *opts) OPT_END() }; struct option *options = base_options; + int (*cbfun)(struct repository *repo, struct replay_opts *opts); + int ret; if (opts->action == REPLAY_PICK) { struct option cp_extra[] = { @@ -223,19 +234,13 @@ static int run_sequencer(int argc, const char **argv, struct replay_opts *opts) opts->strategy = xstrdup(getenv("GIT_TEST_MERGE_ALGORITHM")); free(options); - if (cmd == 'q') { - int ret = sequencer_remove_state(opts); - if (!ret) - remove_branch_state(the_repository, 0); - return ret; - } - if (cmd == 'c') - return sequencer_continue(the_repository, opts); - if (cmd == 'a') - return sequencer_rollback(the_repository, opts); - if (cmd == 's') - return sequencer_skip(the_repository, opts); - return sequencer_pick_revisions(the_repository, opts); + cbfun = cmd == 'q' ? sequencer_remove_branch_state : + cmd == 'c' ? sequencer_continue : + cmd == 'a' ? sequencer_rollback : + cmd == 's' ? sequencer_skip : + sequencer_pick_revisions; + ret = cbfun(the_repository, opts); + return ret; } int cmd_revert(int argc, const char **argv, const char *prefix) From patchwork Fri Dec 30 07:28:10 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: 13084148 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 30431C4332F for ; Fri, 30 Dec 2022 07:28:43 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234662AbiL3H2l (ORCPT ); Fri, 30 Dec 2022 02:28:41 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51846 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234630AbiL3H2Z (ORCPT ); Fri, 30 Dec 2022 02:28:25 -0500 Received: from mail-wm1-x332.google.com (mail-wm1-x332.google.com [IPv6:2a00:1450:4864:20::332]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id F37CF18B3B for ; Thu, 29 Dec 2022 23:28:24 -0800 (PST) Received: by mail-wm1-x332.google.com with SMTP id c65-20020a1c3544000000b003cfffd00fc0so17906051wma.1 for ; Thu, 29 Dec 2022 23:28:24 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=F1s5a5fcs1dWZsAOCL7oPLvyvKLfhYiVkwnXAoypRgA=; b=CmmUu3xWPqH1VzWtJI5O6BQIQh93scCpq+Z+zX+z9egRmjckubA2EZJEB02IXeM9ig dkIlPJWJc6VmRZuFhUsGSdQXMOR9xKoRbpnJoWhEIYFdu7Yql08D/XrdnfbTYkC/rUoV XLjwzc98woKV0/XtDiEIOQfIn94hZBnKY55Iw5CP7JWURbenz8K8bmUFQIvuZjjNU6OE xv8KfJn0B1gZxMbAjuE3+MC7u+A1GZIWrxDyLRL9khG+KLeAJ83aAtNNhaW8nJUDed8P RgV9sZuuoSfAAzMbROmPjzTbd1kkbDOqagzVCQl8MKCLJfL/4XB6cOg7kZYfRjsufctW 8cYg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=F1s5a5fcs1dWZsAOCL7oPLvyvKLfhYiVkwnXAoypRgA=; b=YY5akgyy3EELaIhia8snszyGLOCCv1QaAUa7ApJ/FTmRssCYbJ+bbDS7pI9OcvDNeA to6SBOlv68TvQkduM5QnnuJlF6fCVb3aRRgZZyZ/T147+uhgrT0Up7XVKMaCMtNKM879 asKzYKLYP1vHoVhNEMQFRyPuWPKVW4cjd33sZLC6/mcpNtnDXxiwK1jYpg1hyD6aR+1s XYhC9dpaGcQ0GfdfD9y3TQnzjy+6T9LOrCBVIW/MfZPl6C/Q86WIcBa0jtFs6ZJrpebP mZFtEBlJTf87siKGKdGKpO4jEiK0jSmg/gqY6WSlpGmcuXisGgM+FRz0VUiuX7NP4LEH yqpw== X-Gm-Message-State: AFqh2kpSe+t/nSFsQ06i2pdmds4xBaxVnu38CY6zjAbE7opwPSyg7KtQ ZRDBecoPWTc+E0RdtdeGW7q921mW+DRWiw== X-Google-Smtp-Source: AMrXdXuk/kCbT9AdFRLQtFQryVk/XR9O8gznLuXK0wTbX2RvbVpJgmaOPE+/CfXzX1jwmDckgsE7RA== X-Received: by 2002:a1c:7c14:0:b0:3d1:f74d:4f60 with SMTP id x20-20020a1c7c14000000b003d1f74d4f60mr24928761wmc.22.1672385303198; Thu, 29 Dec 2022 23:28:23 -0800 (PST) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id v13-20020a05600c444d00b003d998412db6sm6526449wmn.28.2022.12.29.23.28.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 29 Dec 2022 23:28:22 -0800 (PST) From: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= To: git@vger.kernel.org Cc: Phillip Wood , Johannes Schindelin , Junio C Hamano , Taylor Blau , =?utf-8?q?Ren=C3=A9_Scharfe?= , =?utf-8?b?w4Z2YXIgQXJuZmo=?= =?utf-8?b?w7Zyw7AgQmphcm1hc29u?= Subject: [PATCH 05/10] builtin/revert.c: fix common leak by using replay_opts_release() Date: Fri, 30 Dec 2022 08:28:10 +0100 Message-Id: X-Mailer: git-send-email 2.39.0.1153.g589e4efe9dc In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org Use the replay_opts_release() function introduced in a preceding commit to fix a memory leak in run_sequencer(). Signed-off-by: Ævar Arnfjörð Bjarmason --- builtin/revert.c | 1 + t/t3419-rebase-patch-id.sh | 1 + t/t3425-rebase-topology-merges.sh | 2 ++ t/t3501-revert-cherry-pick.sh | 1 + t/t3502-cherry-pick-merge.sh | 1 + t/t3503-cherry-pick-root.sh | 1 + t/t3506-cherry-pick-ff.sh | 1 + t/t3511-cherry-pick-x.sh | 1 + 8 files changed, 9 insertions(+) diff --git a/builtin/revert.c b/builtin/revert.c index e956d125a2b..2f656b25619 100644 --- a/builtin/revert.c +++ b/builtin/revert.c @@ -240,6 +240,7 @@ static int run_sequencer(int argc, const char **argv, struct replay_opts *opts) cmd == 's' ? sequencer_skip : sequencer_pick_revisions; ret = cbfun(the_repository, opts); + replay_opts_release(opts); return ret; } diff --git a/t/t3419-rebase-patch-id.sh b/t/t3419-rebase-patch-id.sh index 7181f176b81..6c61f240cf9 100755 --- a/t/t3419-rebase-patch-id.sh +++ b/t/t3419-rebase-patch-id.sh @@ -5,6 +5,7 @@ test_description='git rebase - test patch id computation' GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME +TEST_PASSES_SANITIZE_LEAK=true . ./test-lib.sh scramble () { diff --git a/t/t3425-rebase-topology-merges.sh b/t/t3425-rebase-topology-merges.sh index 63acc1ea4da..a16428bdf54 100755 --- a/t/t3425-rebase-topology-merges.sh +++ b/t/t3425-rebase-topology-merges.sh @@ -1,6 +1,8 @@ #!/bin/sh test_description='rebase topology tests with merges' + +TEST_PASSES_SANITIZE_LEAK=true . ./test-lib.sh . "$TEST_DIRECTORY"/lib-rebase.sh diff --git a/t/t3501-revert-cherry-pick.sh b/t/t3501-revert-cherry-pick.sh index 1f4cfc37449..2f3e3e24169 100755 --- a/t/t3501-revert-cherry-pick.sh +++ b/t/t3501-revert-cherry-pick.sh @@ -13,6 +13,7 @@ test_description='test cherry-pick and revert with renames 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 setup ' diff --git a/t/t3502-cherry-pick-merge.sh b/t/t3502-cherry-pick-merge.sh index 5495eacfec1..1b2c0d6aca6 100755 --- a/t/t3502-cherry-pick-merge.sh +++ b/t/t3502-cherry-pick-merge.sh @@ -11,6 +11,7 @@ test_description='cherry picking and reverting a merge 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 setup ' diff --git a/t/t3503-cherry-pick-root.sh b/t/t3503-cherry-pick-root.sh index 95fe4feaeee..76d393dc8a3 100755 --- a/t/t3503-cherry-pick-root.sh +++ b/t/t3503-cherry-pick-root.sh @@ -5,6 +5,7 @@ test_description='test cherry-picking (and reverting) a root commit' 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 setup ' diff --git a/t/t3506-cherry-pick-ff.sh b/t/t3506-cherry-pick-ff.sh index 7e11bd4a4c5..b71bad17b85 100755 --- a/t/t3506-cherry-pick-ff.sh +++ b/t/t3506-cherry-pick-ff.sh @@ -5,6 +5,7 @@ test_description='test cherry-picking with --ff option' 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 setup ' diff --git a/t/t3511-cherry-pick-x.sh b/t/t3511-cherry-pick-x.sh index 84a587daf3a..dd5d92ef302 100755 --- a/t/t3511-cherry-pick-x.sh +++ b/t/t3511-cherry-pick-x.sh @@ -2,6 +2,7 @@ test_description='Test cherry-pick -x and -s' +TEST_PASSES_SANITIZE_LEAK=true . ./test-lib.sh pristine_detach () { From patchwork Fri Dec 30 07:28:11 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: 13084149 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 2CBBEC4332F for ; Fri, 30 Dec 2022 07:28:45 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234667AbiL3H2o (ORCPT ); Fri, 30 Dec 2022 02:28:44 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51866 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234626AbiL3H20 (ORCPT ); Fri, 30 Dec 2022 02:28:26 -0500 Received: from mail-wm1-x331.google.com (mail-wm1-x331.google.com [IPv6:2a00:1450:4864:20::331]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CE9CB18E08 for ; Thu, 29 Dec 2022 23:28:25 -0800 (PST) Received: by mail-wm1-x331.google.com with SMTP id b24-20020a05600c4a9800b003d21efdd61dso14685031wmp.3 for ; Thu, 29 Dec 2022 23:28:25 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=E5IAFNj8WEn1g7arBzvenIlOV47hR/aLwavS/6SIC9c=; b=FdRFLLoQJ/UJq4gyRxYun9YTsjXYSwP96v8Em9wn9+Zo/NSp5gR9jW+NyaqQdFeRtg 4igVY58U71yYY0gWGPgqa4/++7rIGLywsPPNF2dCcavxERtmADBceWBiZdyGbMgZ3bTX l7O5nBWck9AQzx5VERcnS2FNWLrcQsKoQOmr7kV9w2O66mRt0pcNnPX/D3/UzS1mERPW 0qo1hYdY75YBaU30xnEXrNjcDJdIF2OOZ23MUhd5qV+/2XDpg1/kZnuhj9Hn0W9Jk/8j zrA5asM7Cev9/EBrRPP7ktmWf+r6e1qRVg017ZHSiag7AnVMefCJbOKNYOMDk23Bh8i1 XWpA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=E5IAFNj8WEn1g7arBzvenIlOV47hR/aLwavS/6SIC9c=; b=snhPiGG8kDdeXc7tYfSKrP0I5M307e7bAgxCSIxdn1a4R+npIlR4KJ+QjtnlYc+kiS STeGkR5iXT/9yGKznY4ZI4/AZFazAykMnaDa4tevKUNbc/saO10RX4++7TEnr08u5Yvk esxV68y7OMlmrCJAHVQeyL6+LoQCNB1+zIZAd9qXX9GPvYSjCZwS6wsCR+KifVDzi07D S3p9d/g8M5A87s96/25I2kfEl/8GSqqEsAmVGlszrKHbDKNva0DzrrYCL+cU+8GCypF7 3O1RJ2GXwPXlWIeXXwP4N1wtokxFWRMhC54FB5dqJUi7aqM0/1i+1NxmQz7XF2ekzElA qczg== X-Gm-Message-State: AFqh2kqIZ9M3slegfOFtSyI1rLRhj/l64NGHmjuiK0RiwM1lzmjvfpn/ Dr4Hq7EY2BYE6qzcbQ9XfPaTDcSvM5NAcg== X-Google-Smtp-Source: AMrXdXsvVEPJqGvlXxtY4Q+CN2ie/Gs5CH+shPFQTPr1TyNTXtY+OeEwmwwXdkTSY6I1pcg/9BIY6Q== X-Received: by 2002:a05:600c:4c21:b0:3cf:f18b:327e with SMTP id d33-20020a05600c4c2100b003cff18b327emr22361128wmp.4.1672385304069; Thu, 29 Dec 2022 23:28:24 -0800 (PST) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id v13-20020a05600c444d00b003d998412db6sm6526449wmn.28.2022.12.29.23.28.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 29 Dec 2022 23:28:23 -0800 (PST) From: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= To: git@vger.kernel.org Cc: Phillip Wood , Johannes Schindelin , Junio C Hamano , Taylor Blau , =?utf-8?q?Ren=C3=A9_Scharfe?= , =?utf-8?b?w4Z2YXIgQXJuZmo=?= =?utf-8?b?w7Zyw7AgQmphcm1hc29u?= Subject: [PATCH 06/10] builtin/revert.c: move free-ing of "revs" to replay_opts_release() Date: Fri, 30 Dec 2022 08:28:11 +0100 Message-Id: X-Mailer: git-send-email 2.39.0.1153.g589e4efe9dc In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org In [1] and [2] I added the code being moved here to cmd_revert() and cmd_cherry_pick(), now that we've got a "replay_opts_release()" for the "struct replay_opts" it should know how to free these "revs", rather than having these users reach into the struct to free its individual members. As explained in earlier change we should be using FREE_AND_NULL() in replay_opts_release() rather than free(). 1. d1ec656d68f (cherry-pick: free "struct replay_opts" members, 2022-11-08) 2. fd74ac95ac3 (revert: free "struct replay_opts" members, 2022-07-01) Signed-off-by: Ævar Arnfjörð Bjarmason --- builtin/revert.c | 8 ++------ sequencer.c | 3 +++ 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/builtin/revert.c b/builtin/revert.c index 2f656b25619..b9fb13c515a 100644 --- a/builtin/revert.c +++ b/builtin/revert.c @@ -254,9 +254,7 @@ int cmd_revert(int argc, const char **argv, const char *prefix) res = run_sequencer(argc, argv, &opts); if (res < 0) die(_("revert failed")); - if (opts.revs) - release_revisions(opts.revs); - free(opts.revs); + replay_opts_release(&opts); return res; } @@ -268,9 +266,7 @@ int cmd_cherry_pick(int argc, const char **argv, const char *prefix) opts.action = REPLAY_PICK; sequencer_init_config(&opts); res = run_sequencer(argc, argv, &opts); - if (opts.revs) - release_revisions(opts.revs); - free(opts.revs); + replay_opts_release(&opts); if (res < 0) die(_("cherry-pick failed")); return res; diff --git a/sequencer.c b/sequencer.c index e29a97b6caa..47367e66842 100644 --- a/sequencer.c +++ b/sequencer.c @@ -362,6 +362,9 @@ void replay_opts_release(struct replay_opts *opts) opts->xopts_nr = 0; FREE_AND_NULL(opts->xopts); strbuf_release(&opts->current_fixups); + if (opts->revs) + release_revisions(opts->revs); + FREE_AND_NULL(opts->revs); } int sequencer_remove_state(struct replay_opts *opts) From patchwork Fri Dec 30 07:28:12 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: 13084150 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 09E9EC4332F for ; Fri, 30 Dec 2022 07:28:48 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234531AbiL3H2q (ORCPT ); Fri, 30 Dec 2022 02:28:46 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51882 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234635AbiL3H21 (ORCPT ); Fri, 30 Dec 2022 02:28:27 -0500 Received: from mail-wm1-x32e.google.com (mail-wm1-x32e.google.com [IPv6:2a00:1450:4864:20::32e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E9E8718E02 for ; Thu, 29 Dec 2022 23:28:26 -0800 (PST) Received: by mail-wm1-x32e.google.com with SMTP id k26-20020a05600c1c9a00b003d972646a7dso11611317wms.5 for ; Thu, 29 Dec 2022 23:28:26 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=IG4cljO9A+mkjB7FbMUFvgaidw60Uzkh3j9pfp/Ay9k=; b=BVugXgCnfp3o7lcq8EguVTbNtK4Jp3R+oQ0wZdzlbVI3lFIckhDJmDn0DGnAlDLPDz 6cxt2Wev6FMCWw7C/UvC+qeAFUymWrafa/xbEMhchpnnsAAWIYFT10DKgv/5qFHeODAV 3Gcopwz+Zc6+QIulAEvyagoAjA7ypWuJAIWVkftrBNjgpzBD1ucQUk6l8m1BEXf9lrO5 WegaRrPHGTlkMSNPivWZQpUCxtQazAcbUB1RIXTZXwxv8nhea6xmt07b3/qJDdlsCwFL S3qHcPBhc0m8DxbCu9gDXYKrGk7VZLdkP1+u2TAe/cpPaMnALI1KkGuGnn9X7B2Kc+rP 7wJQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=IG4cljO9A+mkjB7FbMUFvgaidw60Uzkh3j9pfp/Ay9k=; b=RHhnActJmDYWMkpOBXe4vG/V82J9oh+zsIvcfrRYKpZcw2EykNKqNQ3Zo0CYiE/qja Gr19tb0G/VDrA6r23UnPdBfUJ5J2LOQ+s5X6YERktRMyRyQwDCEPiRb4DI0JvKVV+Pn6 4xHHpQyS6iQ9D4CGK0yyHhAoSCa36/CyR8E7qZwFKTQquZS5C0mrBDi+xebRQqp8reMI D9DUymyaOhOH6uRLjVnYiOYMkxxckeXGKfJroCyW4lXoFB/EVP/u6pbot/ijjCi/iEKb H6xr5lO9QKVvUWcFRQHIRfqVejhbllHPLZe8A2F2T4QX98BId1zHAxElE9BkIBZpUfSt 4ukA== X-Gm-Message-State: AFqh2krydMzuRnahlRHQi35lQstTaPK9XNItmMFb8HJHberGNA3Pc4aC 43DqxISuwQ5/v184ci7X7o8Oy6kesKo6nA== X-Google-Smtp-Source: AMrXdXuE6+AqZCDz8viY8dQfiptDtpeNxTBNsgq5c1XAt1sOvSLMHEEAmoF5p6+xUF0bDs0bMWRRIw== X-Received: by 2002:a05:600c:a10:b0:3d2:2904:dfe9 with SMTP id z16-20020a05600c0a1000b003d22904dfe9mr25396787wmp.21.1672385305152; Thu, 29 Dec 2022 23:28:25 -0800 (PST) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id v13-20020a05600c444d00b003d998412db6sm6526449wmn.28.2022.12.29.23.28.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 29 Dec 2022 23:28:24 -0800 (PST) From: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= To: git@vger.kernel.org Cc: Phillip Wood , Johannes Schindelin , Junio C Hamano , Taylor Blau , =?utf-8?q?Ren=C3=A9_Scharfe?= , =?utf-8?b?w4Z2YXIgQXJuZmo=?= =?utf-8?b?w7Zyw7AgQmphcm1hc29u?= Subject: [PATCH 07/10] builtin/rebase.c: fix "options.onto_name" leak Date: Fri, 30 Dec 2022 08:28:12 +0100 Message-Id: X-Mailer: git-send-email 2.39.0.1153.g589e4efe9dc In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org In [1] we started saving away the earlier xstrdup()'d "options.onto_name" assignment to free() it, but when [2] added this "keep_base" branch it didn't free() the already assigned "squash_onto_name" before re-assigning to "options.onto_name". Let's do that, and fix the memory leak. 1. 9dba809a69a (builtin rebase: support --root, 2018-09-04) 2. 414d924beb4 (rebase: teach rebase --keep-base, 2019-08-27) Signed-off-by: Ævar Arnfjörð Bjarmason --- builtin/rebase.c | 3 ++- t/t3416-rebase-onto-threedots.sh | 1 + 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/builtin/rebase.c b/builtin/rebase.c index 91bf55be6e6..f7fd20d71c0 100644 --- a/builtin/rebase.c +++ b/builtin/rebase.c @@ -1658,7 +1658,8 @@ int cmd_rebase(int argc, const char **argv, const char *prefix) strbuf_addstr(&buf, options.upstream_name); strbuf_addstr(&buf, "..."); strbuf_addstr(&buf, branch_name); - options.onto_name = xstrdup(buf.buf); + free(squash_onto_name); + options.onto_name = squash_onto_name = xstrdup(buf.buf); } else if (!options.onto_name) options.onto_name = options.upstream_name; if (strstr(options.onto_name, "...")) { diff --git a/t/t3416-rebase-onto-threedots.sh b/t/t3416-rebase-onto-threedots.sh index ea501f2b42b..f8c4ed78c9e 100755 --- a/t/t3416-rebase-onto-threedots.sh +++ b/t/t3416-rebase-onto-threedots.sh @@ -5,6 +5,7 @@ test_description='git rebase --onto A...B' GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME +TEST_PASSES_SANITIZE_LEAK=true . ./test-lib.sh . "$TEST_DIRECTORY/lib-rebase.sh" From patchwork Fri Dec 30 07:28:13 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: 13084151 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 B72E9C4332F for ; Fri, 30 Dec 2022 07:28:50 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234676AbiL3H2s (ORCPT ); Fri, 30 Dec 2022 02:28:48 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51880 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234637AbiL3H21 (ORCPT ); Fri, 30 Dec 2022 02:28:27 -0500 Received: from mail-wm1-x32b.google.com (mail-wm1-x32b.google.com [IPv6:2a00:1450:4864:20::32b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DA07C18B3B for ; Thu, 29 Dec 2022 23:28:26 -0800 (PST) Received: by mail-wm1-x32b.google.com with SMTP id bg13-20020a05600c3c8d00b003d9712b29d2so12261510wmb.2 for ; Thu, 29 Dec 2022 23:28:26 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=glxLF5JOMMBpOG/qOaZ0p4DH53k460H30pO9Y+0fzp4=; b=jc7fagUZPqHNU7gc28zj18GgIApq/Foqrt+lRMSwmB84t7CxeaK5P4ueUS0UlRlXNf O+rAUeuuR8E7nhi12V+828z5JnpjSkcaWls8gBWA5Kbr/17ftBOmY4675pUTg5BBWSNx qt5ihKKLx+NuKQlo8R4fAeyQrL4HnE3l5038aWmRvVDAtsHIcElc4+v0ir4Eb+7KN5vi VOT5CmN2iyXZw98+nTKWfZQg/D//fmgizUzXKQFXhAi3Jukh9Amjpy4BaNf768WtO1Mo IjK6n6KH5C1lZxN9qxImTnn1BeE1SRORmVqCHwF5mYiYgULR0YvVedTfOBo3E+WyF+87 an6w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=glxLF5JOMMBpOG/qOaZ0p4DH53k460H30pO9Y+0fzp4=; b=ThWbig8QLfhH7wB7q7evazS5DUI3BTBMqK3m4rLDedjIxhNCp6KSFhjqdCMcua3LXy J8ZTZBoX539Bv6tGDW6UpZwlbqoLazcFuaVE5TiZB/iZgH3jnqABTjkqoinP6Ti45SYe O+xMfirn3f9BT7VOac5RZR+oPL40omf32FxGM0APJZqcoBeXapt/fkTFH19gn5h/21/k Gub/ImIC2q1kHiOsRvwdZTsSqEjna90cRJv68Y//DssQp6Vt/GRkev61SGToxl+WeJuD Z9Ix4nSkucAH25z0gvPwtN6kmqwnU9kJ8pE9f7Dpaxg8kBpDHz0Ph7ScPZ50CtDjOhIR kEAA== X-Gm-Message-State: AFqh2ko1dn8ly4f2ILUkrfjeCRmG4nFSZYoJG1AqbogVk+GYdapayNrp 0Xt5aZTR18j27EQRb2iWxS7LAfhRnVVQ7w== X-Google-Smtp-Source: AMrXdXtQerBAqhIf6TxTTV0o22TRyGeQDT5HCjirrf0O5rB1uDTNQbxb34pcjIvuOEd186C6LCQagQ== X-Received: by 2002:a05:600c:1e10:b0:3d3:404a:8a1a with SMTP id ay16-20020a05600c1e1000b003d3404a8a1amr25262053wmb.11.1672385306078; Thu, 29 Dec 2022 23:28:26 -0800 (PST) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id v13-20020a05600c444d00b003d998412db6sm6526449wmn.28.2022.12.29.23.28.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 29 Dec 2022 23:28:25 -0800 (PST) From: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= To: git@vger.kernel.org Cc: Phillip Wood , Johannes Schindelin , Junio C Hamano , Taylor Blau , =?utf-8?q?Ren=C3=A9_Scharfe?= , =?utf-8?b?w4Z2YXIgQXJuZmo=?= =?utf-8?b?w7Zyw7AgQmphcm1hc29u?= Subject: [PATCH 08/10] sequencer.c: always free() the "msgbuf" in do_pick_commit() Date: Fri, 30 Dec 2022 08:28:13 +0100 Message-Id: X-Mailer: git-send-email 2.39.0.1153.g589e4efe9dc In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org In [1] the strbuf_release(&msgbuf) was moved into this do_pick_commit(), but didn't take into account the case of [2], where we'd return before the strbuf_release(&msgbuf). Then when the "fixup" support was added in [3] this leak got worse, as we added another place where we'd "return" before reaching the strbuf_release(). Let's move it to a "cleanup" label, and use an appropriate "goto". It may or may not be safe to combine the existing "leave" and "cleanup" labels, but this change doesn't attempt to answer that question. Let's instead avoid calling update_abort_safety_file() in these cases, as we didn't do so before. 1. 452202c74b8 (sequencer: stop releasing the strbuf in write_message(), 2016-10-21) 2. f241ff0d0a9 (prepare the builtins for a libified merge_recursive(), 2016-07-26) 3. 6e98de72c03 (sequencer (rebase -i): add support for the 'fixup' and 'squash' commands, 2017-01-02) Signed-off-by: Ævar Arnfjörð Bjarmason --- sequencer.c | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/sequencer.c b/sequencer.c index 47367e66842..db8d789fa76 100644 --- a/sequencer.c +++ b/sequencer.c @@ -2280,8 +2280,10 @@ static int do_pick_commit(struct repository *r, reword = 1; else if (is_fixup(command)) { if (update_squash_messages(r, command, commit, - opts, item->flags)) - return -1; + opts, item->flags)) { + res = -1; + goto cleanup; + } flags |= AMEND_MSG; if (!final_fixup) msg_file = rebase_path_squash_msg(); @@ -2291,9 +2293,11 @@ static int do_pick_commit(struct repository *r, } else { const char *dest = git_path_squash_msg(r); unlink(dest); - if (copy_file(dest, rebase_path_squash_msg(), 0666)) - return error(_("could not rename '%s' to '%s'"), - rebase_path_squash_msg(), dest); + if (copy_file(dest, rebase_path_squash_msg(), 0666)) { + res = error(_("could not rename '%s' to '%s'"), + rebase_path_squash_msg(), dest); + goto cleanup; + } unlink(git_path_merge_msg(r)); msg_file = dest; flags |= EDIT_MSG; @@ -2331,7 +2335,6 @@ static int do_pick_commit(struct repository *r, free_commit_list(common); free_commit_list(remotes); } - strbuf_release(&msgbuf); /* * If the merge was clean or if it failed due to conflict, we write @@ -2403,9 +2406,11 @@ static int do_pick_commit(struct repository *r, } leave: + update_abort_safety_file(); +cleanup: free_message(commit, &msg); free(author); - update_abort_safety_file(); + strbuf_release(&msgbuf); return res; } From patchwork Fri Dec 30 07:28:14 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: 13084152 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 05C12C3DA7C for ; Fri, 30 Dec 2022 07:28:53 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234680AbiL3H2w (ORCPT ); Fri, 30 Dec 2022 02:28:52 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51890 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234488AbiL3H22 (ORCPT ); Fri, 30 Dec 2022 02:28:28 -0500 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 2760418E09 for ; Thu, 29 Dec 2022 23:28:28 -0800 (PST) Received: by mail-wm1-x336.google.com with SMTP id m8-20020a05600c3b0800b003d96f801c48so12461030wms.0 for ; Thu, 29 Dec 2022 23:28:28 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=L1ZPJmXOYH57q9HWDEn50ZNiTN5ANy7LrvddcO7M0zQ=; b=dt88fQmEjoQsyIgwuYP8/H8G9KlzU1Chutp0Ih6RuVXFHtIqFf5eavzdR7hylOqpgO +23NzASBY+MSgcfPH4O57RIJtOIgsGqJPKbp34RJ1D5n2Lk1dgWpkhkLhb3DqiwKuUr0 FjWPBHgZo+hrsYtUUYJcsr9GKQY9V6ktA5LQqZibOUsWEbZR6Gk8r2yxWZNHMfe6MhQi WJHuxRw4SkukyaqmgmajF5aPUNt2QEYQcyzvbif+lLiaiLRRO7XIaT4UvOIC7BZgTIqq D2A1pD8xlkuhsv+JYjgKmfToXyVQMBt/hPrMGgRrQ91zZtnX6hElzGKyGzM4NtGz0XDZ t6wA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=L1ZPJmXOYH57q9HWDEn50ZNiTN5ANy7LrvddcO7M0zQ=; b=pER/59Un5yjjGk9wixvDScYkbeh+NWgXP6ck5yi4zjjLq3lhUwrA74gf1HIonLRtVd JD1HOpkA00/Ul5nztdJoD654AA19sIsjYPL6x/fRaNV8dp8+6PK7sl3eE5fDD1NF1ZlS GxPPO28b2Ctp6vEYJahnvqHoCbpaeO3P47AiiPOajNERyjmV92E6QKpNaQE65cFpcd/j h8JbgXXvo0MKAC3cBCqwYgdg0smgxLG0rNT//DIDAb45wk9zaFpa66XRsriMN+F4B82p IWHcTR85b7eejdNuZSZ2aC0hofKocSmsXbheK/vELmYDYDFiH32vbNyTty2e6IcMlkf4 tGBw== X-Gm-Message-State: AFqh2kpUJiNP5w55PkpmmMFg5LLCTTSgSRTtdXDG1BM8TKMvl/xnbeow g78o0OfjBmLpThlpk2CSs9DRWYLCt0Pqew== X-Google-Smtp-Source: AMrXdXvHa7AHZjOWGujlMngfAEv9t1O/Pp9Nt69pfebM7eM5DOiQmY8mckgPhpVqYBg26oRe2pczwQ== X-Received: by 2002:a05:600c:3485:b0:3d0:761b:f86 with SMTP id a5-20020a05600c348500b003d0761b0f86mr21665354wmq.28.1672385307028; Thu, 29 Dec 2022 23:28:27 -0800 (PST) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id v13-20020a05600c444d00b003d998412db6sm6526449wmn.28.2022.12.29.23.28.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 29 Dec 2022 23:28:26 -0800 (PST) From: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= To: git@vger.kernel.org Cc: Phillip Wood , Johannes Schindelin , Junio C Hamano , Taylor Blau , =?utf-8?q?Ren=C3=A9_Scharfe?= , =?utf-8?b?w4Z2YXIgQXJuZmo=?= =?utf-8?b?w7Zyw7AgQmphcm1hc29u?= Subject: [PATCH 09/10] builtin/rebase.c: free() "options.strategy_opts" Date: Fri, 30 Dec 2022 08:28:14 +0100 Message-Id: X-Mailer: git-send-email 2.39.0.1153.g589e4efe9dc In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org When the "strategy_opts" member was added in ba1905a5fef (builtin rebase: add support for custom merge strategies, 2018-09-04) the corresponding free() for it at the end of cmd_rebase() wasn't added, let's do so. Signed-off-by: Ævar Arnfjörð Bjarmason --- builtin/rebase.c | 1 + 1 file changed, 1 insertion(+) diff --git a/builtin/rebase.c b/builtin/rebase.c index f7fd20d71c0..70b037dc43a 100644 --- a/builtin/rebase.c +++ b/builtin/rebase.c @@ -1833,6 +1833,7 @@ int cmd_rebase(int argc, const char **argv, const char *prefix) free(options.gpg_sign_opt); free(options.cmd); free(options.strategy); + free(options.strategy_opts); strbuf_release(&options.git_format_patch_opt); free(squash_onto_name); string_list_clear(&exec, 0); From patchwork Fri Dec 30 07:28:15 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: 13084153 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 5ED75C4332F for ; Fri, 30 Dec 2022 07:28:54 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234681AbiL3H2x (ORCPT ); Fri, 30 Dec 2022 02:28:53 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51900 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234590AbiL3H2a (ORCPT ); Fri, 30 Dec 2022 02:28:30 -0500 Received: from mail-wm1-x330.google.com (mail-wm1-x330.google.com [IPv6:2a00:1450:4864:20::330]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1932618E02 for ; Thu, 29 Dec 2022 23:28:29 -0800 (PST) Received: by mail-wm1-x330.google.com with SMTP id m26-20020a05600c3b1a00b003d9811fcaafso8145809wms.5 for ; Thu, 29 Dec 2022 23:28:29 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=4wvpFhOtK/oOS3AYoU8929IQ/iLt93v8v3gPlzGMwoY=; b=oUj15YMdgxBPbmWHMumizaRPbJH7mLffYsVdwdVCNMJH0LoiuzaLMAdNKeq01aYeBA Z1RIZK4gGgh3ziUzgZAO/nBMFfJnv3oAkcUzqyz8qy/jIZwMoVKCT8uQZtt+AMMdZCSc nsFgRhTyPBda1I1moK3Zy2r4/haseCfqGdEP80/vflBiq9a+fskFT7wofzx7pk1bcBC9 Ci9BjfNAsuRj7tw2Q82S14VZdEBaxibVAvEdBF7K6O1OKAK4jP1/V48C75gTfaZhNkKM V2P+781VjCWefS3bWtDdmdYYG4ectgYihV6wHmsuMHNmUP+xEJUPupCsFjBo1no/+Yf0 SoNw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=4wvpFhOtK/oOS3AYoU8929IQ/iLt93v8v3gPlzGMwoY=; b=05BKv/YEN9L7bEPaQjiV6WsP+xDZoArrU4PIC1yTVbQSid1MaFwEU34moks/wehskd 2PM5hAYFBN5N2Rp/ukq3ojTIKezKtWVCOmWr0iknkpOgBbnfSXdG61/XK0AfoS1VZG5G GYcop62xrqy5IzQrVleI+yr0X2EO8QVra6oMJnwcmspyWCHh2wPt8Ay9fBZX7I8FIBJ3 culPiDcuAnen/SzCipBf2qIykv3jpRzw6LewsCovXxAffvXZJSKfpQc6LSfqS5rA2KbK ZM/cQz7mfIBdgX/pr5tm1biQ49LfqwbgNDX/EOBX53NsxIgXMTBWusEiRU/EJHrM/eCK bUQQ== X-Gm-Message-State: AFqh2krA0zTJggu8D0i7SiKy0FrCFPpryl8xeqM7a4f6Uzo+U7LTCFre yZk1nM8+ylhs9rlk1fEtzIqMZcsNqjOBjQ== X-Google-Smtp-Source: AMrXdXu8bpJl98bSGj8b4IthWW4/kygQKiYj4gV9nlgLglsTbmUSxmfTrvwC7R1WqWrjUJWfIOUIOQ== X-Received: by 2002:a05:600c:c07:b0:3d9:73fe:96f8 with SMTP id fm7-20020a05600c0c0700b003d973fe96f8mr14213308wmb.32.1672385308352; Thu, 29 Dec 2022 23:28:28 -0800 (PST) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id v13-20020a05600c444d00b003d998412db6sm6526449wmn.28.2022.12.29.23.28.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 29 Dec 2022 23:28:27 -0800 (PST) From: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= To: git@vger.kernel.org Cc: Phillip Wood , Johannes Schindelin , Junio C Hamano , Taylor Blau , =?utf-8?q?Ren=C3=A9_Scharfe?= , =?utf-8?b?w4Z2YXIgQXJuZmo=?= =?utf-8?b?w7Zyw7AgQmphcm1hc29u?= Subject: [PATCH 10/10] commit.c: free() revs.commit in get_fork_point() Date: Fri, 30 Dec 2022 08:28:15 +0100 Message-Id: X-Mailer: git-send-email 2.39.0.1153.g589e4efe9dc In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org Fix a memory leak that's been with us since d96855ff517 (merge-base: teach "--fork-point" mode, 2013-10-23). Signed-off-by: Ævar Arnfjörð Bjarmason --- commit.c | 1 + t/t3431-rebase-fork-point.sh | 1 + t/t3432-rebase-fast-forward.sh | 1 + 3 files changed, 3 insertions(+) diff --git a/commit.c b/commit.c index d00780bee5f..8174c927383 100644 --- a/commit.c +++ b/commit.c @@ -1022,6 +1022,7 @@ struct commit *get_fork_point(const char *refname, struct commit *commit) ret = bases->item; cleanup_return: + free(revs.commit); free_commit_list(bases); free(full_refname); return ret; diff --git a/t/t3431-rebase-fork-point.sh b/t/t3431-rebase-fork-point.sh index 70e81363569..4bfc779bb87 100755 --- a/t/t3431-rebase-fork-point.sh +++ b/t/t3431-rebase-fork-point.sh @@ -8,6 +8,7 @@ test_description='git rebase --fork-point test' GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME +TEST_PASSES_SANITIZE_LEAK=true . ./test-lib.sh # A---B---D---E (main) diff --git a/t/t3432-rebase-fast-forward.sh b/t/t3432-rebase-fast-forward.sh index 5086e14c022..7f1a5dd3deb 100755 --- a/t/t3432-rebase-fast-forward.sh +++ b/t/t3432-rebase-fast-forward.sh @@ -8,6 +8,7 @@ test_description='ensure rebase fast-forwards commits when possible' 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 setup '