From patchwork Thu Jan 12 12:45:53 2023 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: 13097922 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 3EE3CC54EBC for ; Thu, 12 Jan 2023 12:46:22 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230194AbjALMqR (ORCPT ); Thu, 12 Jan 2023 07:46:17 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36762 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230253AbjALMqL (ORCPT ); Thu, 12 Jan 2023 07:46:11 -0500 Received: from mail-ej1-x62e.google.com (mail-ej1-x62e.google.com [IPv6:2a00:1450:4864:20::62e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BFD8912ABE for ; Thu, 12 Jan 2023 04:46:07 -0800 (PST) Received: by mail-ej1-x62e.google.com with SMTP id u9so44524101ejo.0 for ; Thu, 12 Jan 2023 04:46:07 -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=Y0Dj9oU82Zo7IAjusFNhK0kFFJBb8/jbusJ6L7C32Oo=; b=N47iXIr6B2tbVz/idjfRZSN4/i5hEMazE6+4UaCOFyJ8YjmiT1gIGDx0fuJt+eVAD2 kERRZakAPI5cDy/48awIqHDH9mBa8cloEysdHhDjQAIx0eUYgaNSMBYKQJpHUwXvtJz2 OlccoEJDptvHvEdokhT+0QiIZ2GuqOp29xw45uioSp+p6KIdv7dbvxe86paPkR7fyX8+ g0ssIot3D4ybooqsAMxwI4WJLi2fvwGXTJ/YAn8rqggxSWIE5xb2Gopj6AAY2xzPcw0R nKJscVTFxr6CCtXbiD7GwMjQAgflnjt8qGe+8ZEMXNh6cHKU898vqU0w5ZHrGhVup6eb 9USw== 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=Y0Dj9oU82Zo7IAjusFNhK0kFFJBb8/jbusJ6L7C32Oo=; b=0K+U6k+1frZrmMHLUUAQ8CiEjZSfVRZ9BIAJL/hjVlovOsNiwx+3NQeafzB1l71gDz R/onx9ftxT0xNobZMCh3ww1GRVu/3s6lt4a67eFqR6U3484YZrrRY4bOA9lZO88bsNPp QnKqdcQA//4BBZZtZJYWcKY8WHNuGFCVkP8pRHKyfkGOtkfpIUeI8szYIxE3mjkBiPqU BXnH8NHuH5BMxiNvhmjBXOXk0sWlpJ+NGCA+ufMPTnn6pop2OJsFeI2colhip+PpxIuP SU9hgHpYUE391Zk4JN6Qr6/O+Y4JaPQOFuU6NJwgj0ihNQxsuD50tZJMQAef7DM2RRda Gssw== X-Gm-Message-State: AFqh2kruyjz5cvpX33PC3SiNngDa0cXl0mRHi8CshsBRAat9xneGiVa8 98p8SSJJ4iolg9XU27OczWLJQzcjpcdFoQ== X-Google-Smtp-Source: AMrXdXvksDXZ182EOsFPJjGYEvOAJFCYlzpjOc0oZ4BT1X+wRVd1OAR/66zyA8LA10VHouuksmNz/g== X-Received: by 2002:a17:906:1baa:b0:859:1a3c:8b5c with SMTP id r10-20020a1709061baa00b008591a3c8b5cmr7444862ejg.53.1673527565846; Thu, 12 Jan 2023 04:46:05 -0800 (PST) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id v17-20020a170906293100b007be301a1d51sm7373523ejd.211.2023.01.12.04.46.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 12 Jan 2023 04:46:05 -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 v2 1/9] rebase: use "cleanup" pattern in do_interactive_rebase() Date: Thu, 12 Jan 2023 13:45:53 +0100 Message-Id: X-Mailer: git-send-email 2.39.0.1205.g2ca064edc27 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 53bbcfbde7c (rebase -i: implement the main part of interactive rebase as a builtin, 2018-09-27), 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 Thu Jan 12 12:45:54 2023 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: 13097923 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 429E7C54EBD for ; Thu, 12 Jan 2023 12:46:27 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230385AbjALMqX (ORCPT ); Thu, 12 Jan 2023 07:46:23 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36660 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230280AbjALMqL (ORCPT ); Thu, 12 Jan 2023 07:46:11 -0500 Received: from mail-ej1-x634.google.com (mail-ej1-x634.google.com [IPv6:2a00:1450:4864:20::634]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BE4C549151 for ; Thu, 12 Jan 2023 04:46:08 -0800 (PST) Received: by mail-ej1-x634.google.com with SMTP id v6so1455741ejg.6 for ; Thu, 12 Jan 2023 04:46:08 -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=oqX3YFUgib2wTNx758+8vQUk4m3JkZZ9lN2zw6tyDNE=; b=OLIg0FaxLo6NJ+7OnubnCI4kTDWlZcufZW9b+bMitgy/Msyr2hgHHq5BBqhIubQeEf Sqn02xSfD8PxytTfpT86kkkNMZ/girG9sKEhRPNXrBO9FcgsESXg2ox5V5EZGBjJLWNh kPHIK43a0w2sVTjwZCId2CddQ/tKDtoJxFl/m5MxYZBpbnS/kCnGkh4erLHOXfB3V2YL uAt57u7ix4L9ikjdYmcD4QrSQu+8VMJfZYMEP9OCaFK+2Mg2jryCgYtwajAJf92zMlS4 +ZSsrLKn0zovVWyv18t9D6OynGKtx1vkN9lNkax6V53ePTqAT2xK137EQZU3+d9dLuY9 QdVA== 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=oqX3YFUgib2wTNx758+8vQUk4m3JkZZ9lN2zw6tyDNE=; b=EgMBLAFrF59IjJODcRXaRhExfSQ5QM4kcEbYBkT75eNRFxODumOmnN+OUHRiK1psKv 7FoZ08wrM0eomH9FbJBiIGrai1KCP2QZ2CoUpk+RBfv/ZT28tDzMq8ormUucG/ebOr5Z pT8maKHa47GNOlGHqYAXJNCqWkLwMPApDw+S+OIwepwC2FIrSv4sD+M+t+Z77741Xabh 2Yg3+tHBcyu296r+spnDDcztoGkJSaiLzW/v3fV1paVd/7GogWqJFeTfEzuaDmX3MA3i 2p6HrtqnSI+wMuAVuzexKJp9zayalF4MiUtffjICAEbIADF35IcM3Aj4xJ17JFT7ve9q 52Gg== X-Gm-Message-State: AFqh2kpjIYST49GtOliw6rQJynhHxzgCE2vSAotn3qd7yikBSWT9KB82 XLWxaqGxE0ey3bKAKTTo9fRnBrTRO1FP/A== X-Google-Smtp-Source: AMrXdXsmTNx124MxwAtXCyjc1IsGr08Ihxp8x/XFCGRdY2dnn0vjK6KeE/Xo/ISzsJFLJt6ny/w+gw== X-Received: by 2002:a17:907:b601:b0:838:9c66:cd30 with SMTP id vl1-20020a170907b60100b008389c66cd30mr68096604ejc.13.1673527566918; Thu, 12 Jan 2023 04:46:06 -0800 (PST) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id v17-20020a170906293100b007be301a1d51sm7373523ejd.211.2023.01.12.04.46.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 12 Jan 2023 04:46:06 -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 v2 2/9] sequencer.c: split up sequencer_remove_state() Date: Thu, 12 Jan 2023 13:45:54 +0100 Message-Id: X-Mailer: git-send-email 2.39.0.1205.g2ca064edc27 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 change here is changing the "int" to a "size_t", which is the correct type, as "xopts_nr" is a "size_t". Signed-off-by: Ævar Arnfjörð Bjarmason --- sequencer.c | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/sequencer.c b/sequencer.c index bcb662e23be..d385bea2bed 100644 --- a/sequencer.c +++ b/sequencer.c @@ -351,10 +351,22 @@ 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; if (is_rebase_i(opts) && strbuf_read_file(&buf, rebase_path_refs_to_delete(), 0) > 0) { @@ -373,14 +385,7 @@ 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); + replay_opts_release(opts); strbuf_reset(&buf); strbuf_addstr(&buf, get_dir(opts)); From patchwork Thu Jan 12 12:45:55 2023 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: 13097925 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 158F4C54EBD for ; Thu, 12 Jan 2023 12:46:31 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231140AbjALMq2 (ORCPT ); Thu, 12 Jan 2023 07:46:28 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36704 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229569AbjALMqN (ORCPT ); Thu, 12 Jan 2023 07:46:13 -0500 Received: from mail-ej1-x62c.google.com (mail-ej1-x62c.google.com [IPv6:2a00:1450:4864:20::62c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CAE6C13E02 for ; Thu, 12 Jan 2023 04:46:09 -0800 (PST) Received: by mail-ej1-x62c.google.com with SMTP id v6so1455836ejg.6 for ; Thu, 12 Jan 2023 04:46:09 -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=mcx3cjAGTOQrSwbZIv3mB8StURZGy/RmwM0Kb5HLt38=; b=afEv7eYcIQ3aMrZ+q+Z3UD0dd893r8nMArKzsh0KYtkjjHyVsQsa+kX0SNI5R6P08U rCDcr1edrTr1Mwje6sR9r5T+MtjNkytr3nUdQDAUgyAcpbad9wLhpUYzNhL8BsMBDY2/ 09yAbJCQ7YrsGnZ/VrQbOobZNlrlRB/uz6JJ+4aySVPuvfT9Z9V33hW39VTRM+NrX3xY UyTIdjicVGibmMtv1SjW6SEc5hupKwaj3FQdEBJivKe/nKAD+/NBz867PdUiTZg/t8Zv LjKPgI4+CbuHwRp7FpfIS5gDDikNIR0qpwdbxB8PuZwW77QvVfY8zZAY6QK7IYKBQiem llOA== 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=mcx3cjAGTOQrSwbZIv3mB8StURZGy/RmwM0Kb5HLt38=; b=LWAjMYHbf0xHJcR3OxRFGgNev+tJ6KcvQLQeCcxp0moEtrq8xyqGdZFCPsM+iFlzTO zQ9gVxpGrgJWYv96E4AAYICByfQvKfLg8wxz4zsMQvgUgFk9JgNkPOXJmblheVcigAAX GrWE3cGyxRLUaHDZQz7lv7G6aYIHBjLygnGuRYbfAps3Hyumq1PmAMU+yxuI8FShWdOm mz0/tt8azenH+ruSCjuztKHrH+tujXcpbEUinu3mtQBBbP0KJ3uwgRExkF6yswbHqQEs 6IWHKDBBI1Vz0/Z22ERgX1m2EL8fLRl9A4EDs8IojdNl/n4+czpgc9tKQEJjeRcA3xcm 0k1g== X-Gm-Message-State: AFqh2kpJ9AnqjH+Sy8mfCiLB91DMOQb6rQ9Z2eQvnnXY2HkkLnvtOFRI vYRNlUg1RBH0fLd0kTVXANSphCpN3h7WCg== X-Google-Smtp-Source: AMrXdXtJ/bT4lGVIhlLq1HpWPJ8EWuKzqh12tStWgfd9Fd8N8nN5+Usstnazugcwxo7GL/emM+QbYg== X-Received: by 2002:a17:907:73c1:b0:7e8:cf25:4b9c with SMTP id es1-20020a17090773c100b007e8cf254b9cmr60290106ejc.59.1673527567952; Thu, 12 Jan 2023 04:46:07 -0800 (PST) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id v17-20020a170906293100b007be301a1d51sm7373523ejd.211.2023.01.12.04.46.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 12 Jan 2023 04:46:07 -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 v2 3/9] rebase & sequencer API: fix get_replay_opts() leak in "rebase" Date: Thu, 12 Jan 2023 13:45:55 +0100 Message-Id: X-Mailer: git-send-email 2.39.0.1205.g2ca064edc27 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 --- builtin/rebase.c | 4 ++++ builtin/revert.c | 2 ++ sequencer.c | 5 ++--- sequencer.h | 1 + t/t3405-rebase-malformed.sh | 1 + t/t3412-rebase-root.sh | 1 + t/t3419-rebase-patch-id.sh | 1 + t/t3423-rebase-reword.sh | 1 + t/t3425-rebase-topology-merges.sh | 2 ++ t/t3437-rebase-fixup-options.sh | 1 + t/t3438-rebase-broken-files.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 + t/t7402-submodule-rebase.sh | 1 + t/t9106-git-svn-commit-diff-clobber.sh | 1 - t/t9164-git-svn-dcommit-concurrent.sh | 1 - 19 files changed, 24 insertions(+), 5 deletions(-) diff --git a/builtin/rebase.c b/builtin/rebase.c index 7141fd5e0c1..5859a5387d8 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: @@ -558,6 +560,7 @@ static int finish_rebase(struct rebase_options *opts) replay.action = REPLAY_INTERACTIVE_REBASE; ret = sequencer_remove_state(&replay); + replay_opts_release(&replay); } else { strbuf_addstr(&dir, opts->state_dir); if (remove_dir_recursively(&dir, 0)) @@ -1331,6 +1334,7 @@ int cmd_rebase(int argc, const char **argv, const char *prefix) replay.action = REPLAY_INTERACTIVE_REBASE; ret = sequencer_remove_state(&replay); + replay_opts_release(&replay); } else { strbuf_reset(&buf); strbuf_addstr(&buf, options.state_dir); diff --git a/builtin/revert.c b/builtin/revert.c index f2d86d2a8f9..1cab16bf3ed 100644 --- a/builtin/revert.c +++ b/builtin/revert.c @@ -251,6 +251,7 @@ int cmd_revert(int argc, const char **argv, const char *prefix) if (opts.revs) release_revisions(opts.revs); free(opts.revs); + replay_opts_release(&opts); return res; } @@ -267,5 +268,6 @@ int cmd_cherry_pick(int argc, const char **argv, const char *prefix) free(opts.revs); if (res < 0) die(_("cherry-pick failed")); + replay_opts_release(&opts); return res; } diff --git a/sequencer.c b/sequencer.c index d385bea2bed..5d8c68912a1 100644 --- a/sequencer.c +++ b/sequencer.c @@ -351,7 +351,7 @@ 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); @@ -359,6 +359,7 @@ static void replay_opts_release(struct replay_opts *opts) free(opts->strategy); for (size_t i = 0; i < opts->xopts_nr; i++) free(opts->xopts[i]); + opts->xopts_nr = 0; free(opts->xopts); strbuf_release(&opts->current_fixups); } @@ -385,8 +386,6 @@ int sequencer_remove_state(struct replay_opts *opts) } } - replay_opts_release(opts); - strbuf_reset(&buf); strbuf_addstr(&buf, get_dir(opts)); if (remove_dir_recursively(&buf, 0)) 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/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/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/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/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/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 () { 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 Thu Jan 12 12:45:56 2023 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: 13097924 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 667F3C61DB3 for ; Thu, 12 Jan 2023 12:46:28 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230499AbjALMq1 (ORCPT ); Thu, 12 Jan 2023 07:46:27 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36764 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229952AbjALMqO (ORCPT ); Thu, 12 Jan 2023 07:46:14 -0500 Received: from mail-ed1-x532.google.com (mail-ed1-x532.google.com [IPv6:2a00:1450:4864:20::532]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DC92C25F for ; Thu, 12 Jan 2023 04:46:10 -0800 (PST) Received: by mail-ed1-x532.google.com with SMTP id v30so26655846edb.9 for ; Thu, 12 Jan 2023 04:46:10 -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=tr+OH0VWd18MYHbL1P+tb7xUYMoJNRdzSn+T+0AHhQ0=; b=PLhzrppKtQrjkh2H6qjdPy0pWiUJjCs+oiWgKco4MDLLEAehTtzeUrMhAwfnGjSs9h RDWh2Bhx14gpZ37bAJRlbyoRj4DKUByKiuJMYBDITFiN3dCBjyvcuiDWmZxeRcLlUrXD xSzJmURzNP/7e8jNjFbbE9011aCfxvm9xVf67AoPxmcjZJj75O4fjslqM4l9XgDHHyT8 mRs69sMepzXnsW5WAz1xduWw0hRYC7msdJqwDVQC+XaQum7ZHcgNP1thL/olrhhDFKyr /cXoOkhlpQNr4uLcwZplI6CWAFbA66iKCF/d9K000OgW1R/t5jiZBYYL4bofRxlshhWJ VDxQ== 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=tr+OH0VWd18MYHbL1P+tb7xUYMoJNRdzSn+T+0AHhQ0=; b=7IHSxkKRrhvvTtwnODbwvLH/gkWqCI6OCcfW/qMIf46xYV8ZQVucl4Ey5nHy6ggBzB 4zbsOS/ONdJOCt/KlLdOFffaBRjZqe7mJLPag9XmAdB6WXzC7j6jXUFAdm7vnBt+AWkQ ziyG4vpEeUTexcfVbzQLrymB+kKjYjN4hxm0/4F2mImEdLAk84IOTkxAYvj2MlL2+PAA Po7TvfplqWKeogMQRCq+nPggLDMaBtouyStrhujn18ernN/arSdsAWZP+ZgfUhiLCxao opQqjMw/EKmPRSneX5C5DzI/Wi74yT0rD+SULhCE1jvsfgIDJs54UmAVOUiyEGRT31GD KAwg== X-Gm-Message-State: AFqh2kqSlsoVNOs2RzFi+7Op8yhUxVyFgA2Fpd/yd7OkfCITyQmk4V36 MkbBO5gytPtoy67p57qrfjYdACLOVAitkg== X-Google-Smtp-Source: AMrXdXujkb5evOhKrjYNV2T5sIch9Fku1/F3jweVw5CLRyApOXrAnF2gATF8XLEF1Yno+Hifw5BAqQ== X-Received: by 2002:a50:eb06:0:b0:46c:b221:8605 with SMTP id y6-20020a50eb06000000b0046cb2218605mr67630296edp.0.1673527568983; Thu, 12 Jan 2023 04:46:08 -0800 (PST) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id v17-20020a170906293100b007be301a1d51sm7373523ejd.211.2023.01.12.04.46.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 12 Jan 2023 04:46:08 -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 v2 4/9] builtin/revert.c: move free-ing of "revs" to replay_opts_release() Date: Thu, 12 Jan 2023 13:45:56 +0100 Message-Id: X-Mailer: git-send-email 2.39.0.1205.g2ca064edc27 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 | 6 ------ sequencer.c | 3 +++ 2 files changed, 3 insertions(+), 6 deletions(-) diff --git a/builtin/revert.c b/builtin/revert.c index 1cab16bf3ed..77d2035616e 100644 --- a/builtin/revert.c +++ b/builtin/revert.c @@ -248,9 +248,6 @@ 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; } @@ -263,9 +260,6 @@ 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); if (res < 0) die(_("cherry-pick failed")); replay_opts_release(&opts); diff --git a/sequencer.c b/sequencer.c index 5d8c68912a1..c729ce77260 100644 --- a/sequencer.c +++ b/sequencer.c @@ -362,6 +362,9 @@ void replay_opts_release(struct replay_opts *opts) opts->xopts_nr = 0; free(opts->xopts); strbuf_release(&opts->current_fixups); + if (opts->revs) + release_revisions(opts->revs); + free(opts->revs); } int sequencer_remove_state(struct replay_opts *opts) From patchwork Thu Jan 12 12:45:57 2023 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: 13097927 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 D87BCC54EBD for ; Thu, 12 Jan 2023 12:46:37 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230140AbjALMqg (ORCPT ); Thu, 12 Jan 2023 07:46:36 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36720 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230040AbjALMqO (ORCPT ); Thu, 12 Jan 2023 07:46:14 -0500 Received: from mail-ej1-x62a.google.com (mail-ej1-x62a.google.com [IPv6:2a00:1450:4864:20::62a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A8D0113DDC for ; Thu, 12 Jan 2023 04:46:11 -0800 (PST) Received: by mail-ej1-x62a.google.com with SMTP id jo4so44488433ejb.7 for ; Thu, 12 Jan 2023 04:46:11 -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=9yW7Z0bTG93hxB1K9CLhY9doKlr5T5GPH1I8DY7Xqa0=; b=c1ZrBa9Ta8hQvh70kwhXaWYo/mzyjblJlePllM0pGc9Kx7zpgbUN3CwOujjKN6HjMp oPd9WrsrESBhpkgdmEoWfNeRaTv9vm3Zyh/KANzfWe0QhBkUAFr43UERl9JByvhiaLLl 8ZTjAu/6uqsIH7ODFF39yCWAZwzlPlshiguzhlHt7FK7b2nDwKevdGY+1pBxvnXVNPh5 kHt5J1TkTi0I6lN4eFj7XvWV1rO5LM2rtCTXUC3PY3rmaop9wnXTshQJVKsIVktgv6yR v0tn7DBC6P2w1luhB++ND1SdDG25kNxEb35Xm6cXVBqijBZWeOscX1Zg8/IFUkbpJWj5 ESdw== 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=9yW7Z0bTG93hxB1K9CLhY9doKlr5T5GPH1I8DY7Xqa0=; b=Ver/E0bvYWzxMFB7YNsuupo1sWr9G1aEIZ9Otn83DhjDTgafFohrw/RMxh+pHax1tJ 7DDTkLY4P6Omgy2b22gWNvjbR3NEcU3p3uB20t0RqjwHknNW1iPzUJ3idmqFYRjfzz3x 9DYkknxRAx7kS4vKAyBcvrY27s9h6MIM4VyT2yFk2MWALzpxRjYYjfIdjZCqAfa3jLEh GROWLgb6j3QTHv9lq85oAxrBexJZzMCNPk5cyBSTR+a95AozuVYmUsQBH0gah+KTvzhj t/K238qja85C6c5K4vkOdyjuZMVrb/JYj0ZzW48K1HY5tQzbMjOyuA8j7gXA0y5Kg45D qC6g== X-Gm-Message-State: AFqh2kp6H7IGv1Wz+KVboYUYurrxzNVpf9rAM/4GYJEXSaZX2UOSDdDM TcfdiBswQBq0Sh0Dgwy0Z0ZjZ7Nv8ypPSA== X-Google-Smtp-Source: AMrXdXvKJK6H8wRU5YB7eOxNkQ6d5fAqSvNdiXbqNFoeINbppvZY3oZOh52+3k8c3iyVvkgtpb6k1g== X-Received: by 2002:a17:907:238e:b0:84d:457a:39d5 with SMTP id vf14-20020a170907238e00b0084d457a39d5mr10377929ejb.44.1673527569910; Thu, 12 Jan 2023 04:46:09 -0800 (PST) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id v17-20020a170906293100b007be301a1d51sm7373523ejd.211.2023.01.12.04.46.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 12 Jan 2023 04:46:09 -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 v2 5/9] builtin/rebase.c: rename "squash_onto_name" to "to_free" Date: Thu, 12 Jan 2023 13:45:57 +0100 Message-Id: X-Mailer: git-send-email 2.39.0.1205.g2ca064edc27 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org The real use of the "squash_onto_name" added in [1] is to keep track of a value for later free()-ing, we don't subsequently use it for anything else. Let's rename it in preparation for re-using it for free()-ing before another assignment to "options.onto_name", which is an outstanding leak that'll be fixed in a subsequent commit. 1. 9dba809a69a (builtin rebase: support --root, 2018-09-04) Signed-off-by: Ævar Arnfjörð Bjarmason --- builtin/rebase.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/builtin/rebase.c b/builtin/rebase.c index 5859a5387d8..0d8c050f6b3 100644 --- a/builtin/rebase.c +++ b/builtin/rebase.c @@ -1036,7 +1036,7 @@ int cmd_rebase(int argc, const char **argv, const char *prefix) const char *rebase_merges = NULL; struct string_list strategy_options = STRING_LIST_INIT_NODUP; struct object_id squash_onto; - char *squash_onto_name = NULL; + char *to_free = NULL; int reschedule_failed_exec = -1; int allow_preemptive_ff = 1; int preserve_merges_selected = 0; @@ -1589,7 +1589,7 @@ int cmd_rebase(int argc, const char **argv, const char *prefix) &squash_onto, NULL, NULL) < 0) die(_("Could not create new root commit")); options.squash_onto = &squash_onto; - options.onto_name = squash_onto_name = + options.onto_name = to_free = xstrdup(oid_to_hex(&squash_onto)); } else options.root_with_onto = 1; @@ -1835,7 +1835,7 @@ int cmd_rebase(int argc, const char **argv, const char *prefix) free(options.cmd); free(options.strategy); strbuf_release(&options.git_format_patch_opt); - free(squash_onto_name); + free(to_free); string_list_clear(&exec, 0); string_list_clear(&strategy_options, 0); return !!ret; From patchwork Thu Jan 12 12:45:58 2023 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: 13097926 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 77CF5C54EBD for ; Thu, 12 Jan 2023 12:46:34 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231174AbjALMqd (ORCPT ); Thu, 12 Jan 2023 07:46:33 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36760 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229518AbjALMqO (ORCPT ); Thu, 12 Jan 2023 07:46:14 -0500 Received: from mail-ej1-x62b.google.com (mail-ej1-x62b.google.com [IPv6:2a00:1450:4864:20::62b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9BC8E20D for ; Thu, 12 Jan 2023 04:46:12 -0800 (PST) Received: by mail-ej1-x62b.google.com with SMTP id hw16so32606059ejc.10 for ; Thu, 12 Jan 2023 04:46:12 -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=AbXwRGMI4zVai4Ck+nY7RdVoSbqITBC+4sRXRy8BiMs=; b=Bv5Dz8MU4ft9pCJMxNCDA+TqBa+RNH/quxUVXsa+rlHkh12rYifasuTmjuvHWEXrL4 nABzvl6DBWFCuTMS5GfM+nPXsVGhA1iKubt4Nc/soxXkHQfcDL7RYx4s78kieZRaWLyA RlAsz8iDZdXinGjhoOAWBKYfZUYwX8uN75VyttqV05TD4RNYm8paw+wum6ARAoxp1TCc 37eXwsyjdIYgUmzZh5gr2EFgVvXlm0P8jlJWEZi0RecaKaBJhS1Mxo9zQPFlDsCrbl4s 1T59s6+loTbYQoQx7aBoIhEhvppo3yg5YSmS5nc5htQgrL1OBkWh8d4j1Sfv28anUsw2 zezw== 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=AbXwRGMI4zVai4Ck+nY7RdVoSbqITBC+4sRXRy8BiMs=; b=A93zOGBRCgmtzXLXTbDY/qr7OMGvui2GIZ7IoIfve7gCuKO65bzSpCOSvyt5nbq20n XnQ7yBX5M0LM7AW+xqcBmAEYa7FcNEBYbusmR/FEnrmdDL/8cMFZrQYsq4vThwHmTvdK +BaMRpZqGqza0hsfh9kTVx/pfb+n4d1yvnTXc/NNC3GyErVD0YxvT6VG6pXq8sQ6JUO4 CgGmyjsoaHDE1/SCyfmjmozZsawN1d+pPq9VwWkK64ZXdbekpRaafJZIdKn1A9i49ziF OAvMtWsGR8br/z6kxMhdFEZKMgX+xREJbwce4J4tlajsWEaxc014fT9jHwfFITbKnLmf 5wmA== X-Gm-Message-State: AFqh2kq33ShdLOWv9F2OhOMKa0o7pc7VJOtQ54o2PnNO0KXVRYlJEMfd 7RuJMmYYOuVhIXShMNC8sAbWGEnb4eKaSw== X-Google-Smtp-Source: AMrXdXtePZJWPN4AdOIcseX01SJB/HUjThmv0ZSDnuQ7EhRV8lv3W78Wwq/P4x70alTUX0QrQoquvA== X-Received: by 2002:a17:907:8c82:b0:7c0:f7b2:b19a with SMTP id td2-20020a1709078c8200b007c0f7b2b19amr71239165ejc.27.1673527570893; Thu, 12 Jan 2023 04:46:10 -0800 (PST) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id v17-20020a170906293100b007be301a1d51sm7373523ejd.211.2023.01.12.04.46.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 12 Jan 2023 04:46:10 -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 v2 6/9] builtin/rebase.c: fix "options.onto_name" leak Date: Thu, 12 Jan 2023 13:45:58 +0100 Message-Id: X-Mailer: git-send-email 2.39.0.1205.g2ca064edc27 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 value 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 0d8c050f6b3..b4857b89f19 100644 --- a/builtin/rebase.c +++ b/builtin/rebase.c @@ -1660,7 +1660,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(to_free); + options.onto_name = to_free = 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 Thu Jan 12 12:45:59 2023 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: 13097928 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 AB838C54EBC for ; Thu, 12 Jan 2023 12:46:43 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230337AbjALMqj (ORCPT ); Thu, 12 Jan 2023 07:46:39 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36612 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230061AbjALMqP (ORCPT ); Thu, 12 Jan 2023 07:46:15 -0500 Received: from mail-ej1-x629.google.com (mail-ej1-x629.google.com [IPv6:2a00:1450:4864:20::629]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 96CC93BB for ; Thu, 12 Jan 2023 04:46:13 -0800 (PST) Received: by mail-ej1-x629.google.com with SMTP id fy8so44344767ejc.13 for ; Thu, 12 Jan 2023 04:46:13 -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=UxzqBi9vERRV4a3rFM7b/HTLMVqDPOMu5xPyScSsmYc=; b=NSdqRka0vcXeTjLBBvtg0oHIDf+FiefPq8pJ5ZdCcNsIlj/AHlSChSgG2IH8ZcL3bE YkymMVfwOQe3kd6yz7jVUxoG9neU2NOi+Jzadhv4kDwTqJIh30mbcuVtInaUJYms9HS3 E5ftPtsxsGEMURgGJwqAIVH49pvEVw0P+FXsS1E44IZOTBks8wianG6oHT59hTZj4h17 u5SUEniFkTL4+z1tAJqhbmwkJ7e96JwmhX/U0mHdD7MNQ2PxvWtSWHNjx8gMoWAkZrzo +aPkNOs4n1E59NkV3FHDrr8NMnfSJZy8tzDTEumkYI4Lfzt/YGqAWgk5/+fwa85zlEQ1 1jsA== 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=UxzqBi9vERRV4a3rFM7b/HTLMVqDPOMu5xPyScSsmYc=; b=fY3CHDE5Y0Gap42EyUEy8uHZL5E02xVEqQFkpTP9gaD6L9Z/A0hUpozPcgC219Grfh 2AuPnx6hGQAxr4qX1HneGKX93NqlgzABtyhZz0nhwWBY8jVdoo8HW70zc9tsWzqlxmfm hti6sRQWIFpuSfG4hI/ZJIi5zVCsgqAnHD9g/sA50Am9Z9X8hE9BO0FVp+/QwGqRc4mS Bpfss/wk6FnWavjEeZ84vJKsUdAOwKPKwTKT7srkcqo/Sll3HxVLCFcQpxxd9eCmNHH7 zHV6LbwdCs3vfcmNztVcx2lKe8jkbdPPfCF2PJNUXIyV6mU8fFiKM+Jbh6/4csi1NkuI v0Hg== X-Gm-Message-State: AFqh2kprpjd1TKAMyzj1grBPJGKOgvHWPfYidJOV5wI0+yahnjElH7+G G73qwHa71SF/RLL5S9syarPGbktjgp18OA== X-Google-Smtp-Source: AMrXdXv7Ul76BJukvxpI5XHcjF16WqMPf8xPceryVemk9nXA3Tpx9njzqnme84mtgiSdtKmZoDJYyQ== X-Received: by 2002:a17:907:8744:b0:7c1:277:cb05 with SMTP id qo4-20020a170907874400b007c10277cb05mr83187658ejc.6.1673527571775; Thu, 12 Jan 2023 04:46:11 -0800 (PST) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id v17-20020a170906293100b007be301a1d51sm7373523ejd.211.2023.01.12.04.46.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 12 Jan 2023 04:46:11 -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 v2 7/9] sequencer.c: always free() the "msgbuf" in do_pick_commit() Date: Thu, 12 Jan 2023 13:45:59 +0100 Message-Id: X-Mailer: git-send-email 2.39.0.1205.g2ca064edc27 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 in this error case we added another place where we'd "return" before reaching the strbuf_release(). This changes the behavior so that we'll call update_abort_safety_file() in these cases where we'd previously "return", but as noted in [4] "update_abort_safety_file() is a no-op when rebasing and you're changing code that is only run when rebasing.". Here "no-op" refers to the early return in update_abort_safety_file() if git_path_seq_dir() doesn't exist. 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) 4. https://lore.kernel.org/git/bcace50b-a4c3-c468-94a3-4fe0c62b3671@dunelm.org.uk/ Signed-off-by: Ævar Arnfjörð Bjarmason --- sequencer.c | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/sequencer.c b/sequencer.c index c729ce77260..31ea9b036cd 100644 --- a/sequencer.c +++ b/sequencer.c @@ -2278,8 +2278,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 leave; + } flags |= AMEND_MSG; if (!final_fixup) msg_file = rebase_path_squash_msg(); @@ -2289,9 +2291,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 leave; + } unlink(git_path_merge_msg(r)); msg_file = dest; flags |= EDIT_MSG; @@ -2329,7 +2333,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,6 +2406,7 @@ static int do_pick_commit(struct repository *r, leave: free_message(commit, &msg); free(author); + strbuf_release(&msgbuf); update_abort_safety_file(); return res; From patchwork Thu Jan 12 12:46:00 2023 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: 13097929 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 8B363C61DB3 for ; Thu, 12 Jan 2023 12:46:45 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231146AbjALMqo (ORCPT ); Thu, 12 Jan 2023 07:46:44 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36610 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230124AbjALMqP (ORCPT ); Thu, 12 Jan 2023 07:46:15 -0500 Received: from mail-ej1-x62f.google.com (mail-ej1-x62f.google.com [IPv6:2a00:1450:4864:20::62f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8FF5217E19 for ; Thu, 12 Jan 2023 04:46:14 -0800 (PST) Received: by mail-ej1-x62f.google.com with SMTP id vm8so44459638ejc.2 for ; Thu, 12 Jan 2023 04:46:14 -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=su2b20tJPkNBsJYxXc4+4zXQMn19sbEWgsfF+5lVhB8=; b=qNHtrKlEQDTwnaDImebrHWaX5ITaiYQzhumjwqqJcUXKkB3D7KtgU4sjWUfOc9bd7/ h3a533KkkcLeQzdddzJbYl78oBpZ9chS5hIp/jlPpTkzLfzC1s/cms9qRBMh69/2pH/I nSDxjf6H0HoqQ0yAXGrGC1c/4M4F0awIU1nJaxnCWD8dcmPjLAOwIfTYE3/DCTAkNR4l 9UELIiDxbBPUyK9P26rkRvCww4t84Jq2NJgiMWpBxP0YAwfQo/z4ajcPbqjNJbJsImuS BD7isf+UN0sYA/GgNjanpMYyVP3TDSCQVfcPrueTudul6Qo3NlsrlUzun8uGh4yJksvq V+Rg== 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=su2b20tJPkNBsJYxXc4+4zXQMn19sbEWgsfF+5lVhB8=; b=QdavG+MjiBG8lNL86Hks2QFn3mn3wGgT/J31L+YDpKmYaaflv+T1BMM/Xh6pXzCP4j a8jinw9i3w5WJqOmmVsZFQkkTELu0FLiW3aoWMjiS52T+TgyT7mSzfXxF6xeYBN9QYHd MXoeA8L9JRjPyaQhbuHO07qe2yI4quPrhqpPI4dMFSax7NqQaMoWHDaoJFZI8CgsATMf zndD+1cRRoeSmfg3tKjf747RQdhQTswDVK8VF4FyKriUL4oXjIkxczozf2nXQIpHwzVf bX4yy5gVP1ulatS4q0BlMwXHF2gfFTKzIhHOY64aeOiT7Cmvw1p3gfvqJUmzGEsPV7uv NewA== X-Gm-Message-State: AFqh2krwgjWIwluVyfK1YnEzEaIRcMDoMS7d8qEAJ1Cl6ylz/dWFZd2K W8bbiReh+u8bOgXTOfYaTIWFDuinPdE/Ag== X-Google-Smtp-Source: AMrXdXsyi3HE7T1hqFuQKe3TOvRLN5HbpVL7C7m5jtOmefm3X2gxKwnCx/InkoM0j7ouKHSMcksI6g== X-Received: by 2002:a17:906:6881:b0:84d:4d6c:a462 with SMTP id n1-20020a170906688100b0084d4d6ca462mr11195890ejr.25.1673527572783; Thu, 12 Jan 2023 04:46:12 -0800 (PST) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id v17-20020a170906293100b007be301a1d51sm7373523ejd.211.2023.01.12.04.46.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 12 Jan 2023 04:46:12 -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 v2 8/9] builtin/rebase.c: free() "options.strategy_opts" Date: Thu, 12 Jan 2023 13:46:00 +0100 Message-Id: X-Mailer: git-send-email 2.39.0.1205.g2ca064edc27 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 b4857b89f19..4a5a34de6e2 100644 --- a/builtin/rebase.c +++ b/builtin/rebase.c @@ -1835,6 +1835,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(to_free); string_list_clear(&exec, 0); From patchwork Thu Jan 12 12:46:01 2023 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: 13097930 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 7A963C54EBC for ; Thu, 12 Jan 2023 12:47:19 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231503AbjALMrQ (ORCPT ); Thu, 12 Jan 2023 07:47:16 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36934 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230430AbjALMqY (ORCPT ); Thu, 12 Jan 2023 07:46:24 -0500 Received: from mail-ej1-x632.google.com (mail-ej1-x632.google.com [IPv6:2a00:1450:4864:20::632]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 81E01496CE for ; Thu, 12 Jan 2023 04:46:20 -0800 (PST) Received: by mail-ej1-x632.google.com with SMTP id ss4so37184402ejb.11 for ; Thu, 12 Jan 2023 04:46: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=Jnf9yzlnX/3YrB4Jj3j2oGQkdEzNXoYMKUG4m/VZ30Q=; b=SrCaHy/XjEx5LBgIyDsL8Ii68l2lebFhqwofMc/61kHcVaWtz7yPhbT8+kvuEJjzHi uW8MzMC5R1ZT2mOeDWZmnhar0RjCXWMSJfl1VhP//on8UE6BsT8oD7T6/vQMJhM6QwNc 7twVB3sS8aoBZaf5k3KemO2H1tlXNxFm9gzSdNhvUH9KzGt8bq3vApvbrZKNF7+ZJyLI hY2K8KXRKxNQowYw4ziBpxJdzp9S5fyEk43zEOqFZiib0/EG5slP6oUkn3S1EUtpasjS /l5VWxzhUHswT85oTXF2JtdYlhwW0vT5s5OL2qAQJUJF5l5yolnNsLdoy6DsSzExXUwE +x7g== 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=Jnf9yzlnX/3YrB4Jj3j2oGQkdEzNXoYMKUG4m/VZ30Q=; b=6G+BII3yFVQCqf9kkRRXKVdvjR7nUmwoOkUeMqR65Y6nznhiA28VsXCf2U22rJ7t0F 6DAX6Ue3+ldJQ6CTKA4zD90g4G9wkc2U0M7mGfhPQPd8ptMeZhiWm57CMgKd+bgaO3Vq gvD/ckwgCL57rSUB/EFBqfRLjXAQLSsGhogdU5ZcP0ZldpjfuG0ihDjYUgwBq32QKvaG q2FilWuscyf1GngsLuj0/H1XmvPnfHbINJz2FlVLkVH2YiaY09IkLIIf5kR+klpNVoBO WTBRKAvos73e+9WqqBOwdd+IiM5NUgI4AzI5xVvbMf26nfFOmqRCFP9dy3o6pnRut7LP G9EA== X-Gm-Message-State: AFqh2kpE7i8EWF7Sf1kt2WcdWdqu94okH7bsw6fwsuFwXuLxdnZYsWmH JeEbQPeBd+KrnNK4U6u/5dG0QrMCa0GBdA== X-Google-Smtp-Source: AMrXdXvJZ+qq1WzxcxyxODtklWYp4GEZ4KHxCtMidVri0g576ueJx2zFXSHmQ6caryJ/r7BL6c9ndA== X-Received: by 2002:a17:907:7fa7:b0:866:6b08:946b with SMTP id qk39-20020a1709077fa700b008666b08946bmr2519728ejc.39.1673527573790; Thu, 12 Jan 2023 04:46:13 -0800 (PST) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id v17-20020a170906293100b007be301a1d51sm7373523ejd.211.2023.01.12.04.46.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 12 Jan 2023 04:46:13 -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 v2 9/9] commit.c: free() revs.commit in get_fork_point() Date: Thu, 12 Jan 2023 13:46:01 +0100 Message-Id: X-Mailer: git-send-email 2.39.0.1205.g2ca064edc27 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 14538a811ae..e433c33bb01 100644 --- a/commit.c +++ b/commit.c @@ -1033,6 +1033,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 '