From patchwork Thu Jun 6 10:29:36 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Steinhardt X-Patchwork-Id: 13688259 Received: from fhigh4-smtp.messagingengine.com (fhigh4-smtp.messagingengine.com [103.168.172.155]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 29DA6328A0 for ; Thu, 6 Jun 2024 10:29:41 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=103.168.172.155 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717669782; cv=none; b=o2Tkm2Mz9qiCIDqT0ZTUH1hna++e9QNJBTWgg2dcA90tAs8k+crY21G87ssxgw4B9ejZii729pQIEikKNoGl9/Y8I9O23ytIo5uLREzNaZMjGYI0s9RXvat11onrlc9aWdFubijBTKK40woOpSSwfXelMsSO4TVdtsILd+p+hnQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717669782; c=relaxed/simple; bh=/AdVA6oi2gEFZOFJD0Z1gQgF+nfRg+Gt0mqT9VoEQ60=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=A7NWcEe4jVzwBIj8y52hHlXssCCibKanKKjmuTUZkpw/FloYiDdpgopY4FJAXuGLFddyKjmK1xBzPEqJvqd8fOHx3pmPyQPYAq+qgJ00F648fiapYPckar/ep2PS34+JqOOUEYJvR2MdtlLMkRnmcuaezGNo4FQI3EpKTt7iD+M= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=pks.im; spf=pass smtp.mailfrom=pks.im; dkim=pass (2048-bit key) header.d=pks.im header.i=@pks.im header.b=ZSc+leWc; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=fzArxOpz; arc=none smtp.client-ip=103.168.172.155 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=pks.im Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=pks.im Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=pks.im header.i=@pks.im header.b="ZSc+leWc"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="fzArxOpz" Received: from compute5.internal (compute5.nyi.internal [10.202.2.45]) by mailfhigh.nyi.internal (Postfix) with ESMTP id 7EA1911401AD; Thu, 6 Jun 2024 06:29:40 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute5.internal (MEProxy); Thu, 06 Jun 2024 06:29:40 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pks.im; h=cc:cc :content-type:content-type:date:date:from:from:in-reply-to :in-reply-to:message-id:mime-version:references:reply-to:subject :subject:to:to; s=fm1; t=1717669780; x=1717756180; bh=U9xvczMRvk Zge9hFefhIEXdxgI9RDORPck5qooUjVYY=; b=ZSc+leWcCJ2jvzV4WjnL4ZrYsA 0+ndGiqqJNnJqTqYCgDiHN5/rRENX02z5q29ntdXmodyLhW1QglP5wEPpdY8eD1i YU2k9SECvn9epe8N3/Zzbnu+TZocV0xoF02BpVKL7g4WKOfx8Gr9H9DHCO8ZU8Wv tO+WwbAomK0xvOnpHfLngUGvb48cFP3EARR/2/GB4aA/U9p2AMDial4hA0mVvMY+ 2LU8hAh4RMrkO8kwWmbWlbZxlYtNUtLuyxwbxSeQOHic//L1PdVw+45a+i6dbBgK bX/3yTOwXPflzNfG68SsO6X4dbwdgIi/3mQdl1WUIys42yknb5qKG/z6azDg== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-type:content-type:date:date :feedback-id:feedback-id:from:from:in-reply-to:in-reply-to :message-id:mime-version:references:reply-to:subject:subject:to :to:x-me-proxy:x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s= fm1; t=1717669780; x=1717756180; bh=U9xvczMRvkZge9hFefhIEXdxgI9R DORPck5qooUjVYY=; b=fzArxOpz5wBpTKKCt85ommyQ+URcKJOCpPSA+1OPOYg6 SfAfT3lSMVfxkzCRuYyqvlPG2tDVDltnSnBSJyku3Zr8CpMrs0L/DX8NEBavKelx sftEWg9To5Hji+MPl+Ras9AEFHVa0FB1v82ZQ/9vQoKkiELHDHqgRHIcpwV1s9wl y8shk/L/8qkVZo1SuysYYsHvEtxMN2Grcospl5k4q2IWJc5O822ujLxxPe6KQVIX NQC2xU50+1ATZTGe72klF7xkA5buK5cxG3LrKOnibCcy4+t05YK083lxmxx9wUvC Zs1fGfXBbpELfxSkYqeL9zc/iHlNxSFPWuAC/e6k6w== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvledrvdelkedgvdelucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne cujfgurhepfffhvfevuffkfhggtggujgesghdtreertddtvdenucfhrhhomheprfgrthhr ihgtkhcuufhtvghinhhhrghrughtuceophhssehpkhhsrdhimheqnecuggftrfgrthhtvg hrnhepueektdevtdffveeljeetgfehheeigeekleduvdeffeeghefgledttdehjeelffet necuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpehmrghilhhfrhhomhepphhsse hpkhhsrdhimh X-ME-Proxy: Feedback-ID: i197146af:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Thu, 6 Jun 2024 06:29:39 -0400 (EDT) Received: by localhost (OpenSMTPD) with ESMTPSA id f2e6c6c0 (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO); Thu, 6 Jun 2024 10:29:08 +0000 (UTC) Date: Thu, 6 Jun 2024 12:29:36 +0200 From: Patrick Steinhardt To: git@vger.kernel.org Cc: Jeff King , Junio C Hamano , Eric Sunshine Subject: [PATCH v5 24/27] builtin/rebase: do not assign default backend to non-constant field Message-ID: <81c69da2e830d04d4fbb2108944d55c8711d4e8b.1717667854.git.ps@pks.im> References: Precedence: bulk X-Mailing-List: git@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: The `struct rebase_options::default_backend` field is a non-constant string, but is being assigned a constant via `REBASE_OPTIONS_INIT`. Fix this by using `xstrdup()` to assign the variable and introduce a new function `rebase_options_release()` that releases memory held by the structure, including the newly-allocated variable. Signed-off-by: Patrick Steinhardt --- builtin/rebase.c | 25 ++++++++++++++++--------- 1 file changed, 16 insertions(+), 9 deletions(-) diff --git a/builtin/rebase.c b/builtin/rebase.c index 14d4f0a5e6..adc990b55e 100644 --- a/builtin/rebase.c +++ b/builtin/rebase.c @@ -135,7 +135,7 @@ struct rebase_options { .type = REBASE_UNSPECIFIED, \ .empty = EMPTY_UNSPECIFIED, \ .keep_empty = 1, \ - .default_backend = "merge", \ + .default_backend = xstrdup("merge"), \ .flags = REBASE_NO_QUIET, \ .git_am_opts = STRVEC_INIT, \ .exec = STRING_LIST_INIT_NODUP, \ @@ -151,6 +151,19 @@ struct rebase_options { .strategy_opts = STRING_LIST_INIT_NODUP,\ } +static void rebase_options_release(struct rebase_options *opts) +{ + free(opts->default_backend); + free(opts->reflog_action); + free(opts->head_name); + strvec_clear(&opts->git_am_opts); + free(opts->gpg_sign_opt); + string_list_clear(&opts->exec, 0); + free(opts->strategy); + string_list_clear(&opts->strategy_opts, 0); + strbuf_release(&opts->git_format_patch_opt); +} + static struct replay_opts get_replay_opts(const struct rebase_options *opts) { struct replay_opts replay = REPLAY_OPTS_INIT; @@ -796,6 +809,7 @@ static int rebase_config(const char *var, const char *value, } if (!strcmp(var, "rebase.backend")) { + FREE_AND_NULL(opts->default_backend); return git_config_string(&opts->default_backend, var, value); } @@ -1833,14 +1847,7 @@ int cmd_rebase(int argc, const char **argv, const char *prefix) cleanup: strbuf_release(&buf); strbuf_release(&revisions); - free(options.reflog_action); - free(options.head_name); - strvec_clear(&options.git_am_opts); - free(options.gpg_sign_opt); - string_list_clear(&options.exec, 0); - free(options.strategy); - string_list_clear(&options.strategy_opts, 0); - strbuf_release(&options.git_format_patch_opt); + rebase_options_release(&options); free(squash_onto_name); free(keep_base_onto_name); return !!ret;