From patchwork Mon Jun 3 09:41:04 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Steinhardt X-Patchwork-Id: 13683495 Received: from wfout4-smtp.messagingengine.com (wfout4-smtp.messagingengine.com [64.147.123.147]) (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 EB8D185656 for ; Mon, 3 Jun 2024 09:41:07 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=64.147.123.147 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717407669; cv=none; b=iM0PTpfFwhG3JRQRdkR26ZpVXOmJQu/L6gOXpuZX6r8R7hNI9OxwDu7PkA3IDN+Se7apj0gL4IxmhR74DRq+U8mhsBaefBJG81Zt/QKs6LW+N2jXToNO/sMBYQIt+IB3nPSc978BfMEbGoTAqgTyHHTQWTgyfAGLlHKn89S1ENs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717407669; c=relaxed/simple; bh=lio3sDbPmmikL3j41zFb3FuHXXv4/8IYB/UMZ6/ZUWc=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=b52oB/Kx1RG5EW8JwR2z9X8b3GR9OSH5oxrWNrn5BSpQyeUwyutBnFBTXnKVvvWRsq2R3IRiEBarAll6FReuPihgkcvsq9+HKnL8IWTRR8ME8/xxceETU5flaBPH/zUUvtzJNITvNQb8N7dtFlkXQ924+jToY3nLCZ+qhsVB05g= 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=a3igbV9T; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=Z0r3UeDq; arc=none smtp.client-ip=64.147.123.147 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="a3igbV9T"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="Z0r3UeDq" Received: from compute7.internal (compute7.nyi.internal [10.202.2.48]) by mailfout.west.internal (Postfix) with ESMTP id 4B0CC1C00090; Mon, 3 Jun 2024 05:41:07 -0400 (EDT) Received: from mailfrontend2 ([10.202.2.163]) by compute7.internal (MEProxy); Mon, 03 Jun 2024 05:41:07 -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=1717407666; x=1717494066; bh=HvGnvMFqmY Xk8kNT9oWT4/pOdSWYuy/xMHTt58GgqDM=; b=a3igbV9TPl2ubEMcxlwMr3s5F+ jS2fsaDvps7SnKIenwxAJLiwZ5Aub9Mi4lAF7LwW4bRjYlP+zaXF0TlIMI5ELEn5 GuqxU/8hJt7Bv/myRiJ3GTca1ea1NBGPH0E5N1FLeGeKuxkM4pPWqhR+IwN9bvrS 9JjogKAMRLMQK+Hc/cdRSQx+QvHXoQ/XEw6XeYg4lRF66oOpzSON4UzyX2TwEAxy 6u2Cr+TNMpVRFokGW4nOIZky8HcIn2Y5Zcr+eZlf964M/3TgX3NBKIin0wwroxOZ Rr6TLZeJyGzPldIItUdoLFBIWB8d6zuhvPJDUY898GpJoP1xV1eVqNF5HKgQ== 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=1717407666; x=1717494066; bh=HvGnvMFqmYXk8kNT9oWT4/pOdSWY uy/xMHTt58GgqDM=; b=Z0r3UeDqkqtXrjKCuQ0cL/hMaSHA6c7zdSj7PMPj6Sfk ZZzk3v1qfoQ6dcz1Yj2BBioX1SV+i80qBr6In+Y+TFnl/ZQlXYHNjpvRGXTW6cUz ESMHgOUPhuIVEdNeNtIzHpHoVISiAog4MsEg+wD0o/ETOP63bfkhyQHvXUWTt8ec rFTa5X+LD3SMedmkBTUwadaNZoq5AJPYMjYxEw1ZJ3jRLte6pBzmetd1DD4kyJxg KSJLpGAbBGXBx+2DJBhp6B9dKdbjycR1J+Yd14dVXW/VlfTIHokZ8r9tK6dTOzqB iSpjLC8Pmub1lBCXJ1rFXuQsWC4CukLNE1ZWrEGjZg== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvledrvdelvddgudelucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucenucfjughrpeffhffvvefukfhfgggtuggjsehgtd erredttddvnecuhfhrohhmpefrrghtrhhitghkucfuthgvihhnhhgrrhguthcuoehpshes phhkshdrihhmqeenucggtffrrghtthgvrhhnpeeukedtvedtffevleejtefgheehieegke eluddvfeefgeehgfeltddtheejleffteenucevlhhushhtvghrufhiiigvpeehnecurfgr rhgrmhepmhgrihhlfhhrohhmpehpshesphhkshdrihhm X-ME-Proxy: Feedback-ID: i197146af:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Mon, 3 Jun 2024 05:41:05 -0400 (EDT) Received: by localhost (OpenSMTPD) with ESMTPSA id b660448a (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO); Mon, 3 Jun 2024 09:40:41 +0000 (UTC) Date: Mon, 3 Jun 2024 11:41:04 +0200 From: Patrick Steinhardt To: git@vger.kernel.org Cc: Jeff King , Junio C Hamano Subject: [PATCH v3 26/27] builtin/merge: always store allocated strings in `pull_twohead` Message-ID: <84c0149c8fadd5b3f002593873bea3d447832f2a.1717402403.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 `pull_twohead` configuration may sometimes contain an allocated string, and sometimes it may contain a string constant. Refactor this to instead always store an allocated string such that we can release its resources without risk. While at it, manage the lifetime of other config strings, as well. Note that we explicitly don't free `cleanup_arg` here. This is because the variable may be assigned a string constant via command line options. Signed-off-by: Patrick Steinhardt --- builtin/merge.c | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/builtin/merge.c b/builtin/merge.c index daed2d4e1e..fb3eb15b89 100644 --- a/builtin/merge.c +++ b/builtin/merge.c @@ -611,17 +611,19 @@ static int git_merge_config(const char *k, const char *v, return 0; } - if (!strcmp(k, "merge.diffstat") || !strcmp(k, "merge.stat")) + if (!strcmp(k, "merge.diffstat") || !strcmp(k, "merge.stat")) { show_diffstat = git_config_bool(k, v); - else if (!strcmp(k, "merge.verifysignatures")) + } else if (!strcmp(k, "merge.verifysignatures")) { verify_signatures = git_config_bool(k, v); - else if (!strcmp(k, "pull.twohead")) + } else if (!strcmp(k, "pull.twohead")) { + FREE_AND_NULL(pull_twohead); return git_config_string(&pull_twohead, k, v); - else if (!strcmp(k, "pull.octopus")) + } else if (!strcmp(k, "pull.octopus")) { + FREE_AND_NULL(pull_octopus); return git_config_string(&pull_octopus, k, v); - else if (!strcmp(k, "commit.cleanup")) + } else if (!strcmp(k, "commit.cleanup")) { return git_config_string(&cleanup_arg, k, v); - else if (!strcmp(k, "merge.ff")) { + } else if (!strcmp(k, "merge.ff")) { int boolval = git_parse_maybe_bool(v); if (0 <= boolval) { fast_forward = boolval ? FF_ALLOW : FF_NO; @@ -1294,7 +1296,7 @@ int cmd_merge(int argc, const char **argv, const char *prefix) if (!pull_twohead) { char *default_strategy = getenv("GIT_TEST_MERGE_ALGORITHM"); if (default_strategy && !strcmp(default_strategy, "ort")) - pull_twohead = "ort"; + pull_twohead = xstrdup("ort"); } init_diff_ui_defaults(); @@ -1793,6 +1795,8 @@ int cmd_merge(int argc, const char **argv, const char *prefix) } strbuf_release(&buf); free(branch_to_free); + free(pull_twohead); + free(pull_octopus); discard_index(the_repository->index); return ret; }