From patchwork Fri May 24 10:04:41 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Steinhardt X-Patchwork-Id: 13673000 Received: from fout4-smtp.messagingengine.com (fout4-smtp.messagingengine.com [103.168.172.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 61C9A84E09 for ; Fri, 24 May 2024 10:04:45 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=103.168.172.147 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716545086; cv=none; b=u7SVipF2+LAwrVFueeI218YXXMD+koIuNwn1t+tioK4hjtIW0AGFNbPeLostBL0Ie8rxjaK1pBsaFDnp7P0HvQmJVNTxWLsMKeQivOwCl+OX53d3MbTh7D2lj1sZsMmykGHFAiYm4uVRcXmDT5t3ORvfF14QTgblB5oh9LIFvp8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716545086; c=relaxed/simple; bh=tOxNMGEpmwHDkua7F95l0T2dyLB9Q4/JjJQQTksg4n4=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=UCVVXlGOFS5rnnbgYvqNdkSaXkNKehAGo05DVLtMlhBhzYYm3r47KLJzQ2Ix8nzHJ3PmzzxRbNWyLIjtaENmh55NvfGc3FsV+JMpxTKtdBigcm4PiHMT6B5TVEbINZa2oFwpY7o3ORiXELFt5bN4HkasW0YSS+xhP5b/x8rKwaI= 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=Rb9dwGuK; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=CXh5PJ+X; arc=none smtp.client-ip=103.168.172.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="Rb9dwGuK"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="CXh5PJ+X" Received: from compute6.internal (compute6.nyi.internal [10.202.2.47]) by mailfout.nyi.internal (Postfix) with ESMTP id B8C351380128; Fri, 24 May 2024 06:04:44 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute6.internal (MEProxy); Fri, 24 May 2024 06:04:44 -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=1716545084; x=1716631484; bh=ipkRLEswhI XjKTjeP13Ml4/rTVIwOqd0g/d5rxJejsA=; b=Rb9dwGuK0/65jAn/+ORb3U28NN Ufctp3eWWZZXY56WkIuAsfYY3NiifpeA7qzKHjnGV2+0EwgFDoDuKgVuWyaz5Ei/ xCXsZVb6NyOgTmiqF+KDi06DBLOvg9LFC6SBBTNO1kwvmOAdUf6v0DrHh5WjojxC klFJZg9x/3pT6L5k3VfYZzH7+pb+SshE/Y/jYIzX/LJVaf41zK27yJWXF4uemoZ7 SevyZv5uKAxOtvFN79ujOJvtSdVUR2Dzs7y5+DIwyZS+2VJh6fHs3x/TmT2PxPny f7DGjTlpp5dMMCV4omYM/Iu5yR0QwaJ54CMBZnwC5KJOtHGvSpsQnb7JfwXA== 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=1716545084; x=1716631484; bh=ipkRLEswhIXjKTjeP13Ml4/rTVIw Oqd0g/d5rxJejsA=; b=CXh5PJ+XK7IgNLzXnUIzK0FSQFJDDFhsd6RVXNcymm4f e+Bsk5YTgxgPtFGw12dK4wVQFtiM3QwUN2Po5Ghbbk2Zw7GUfCk0GgG9rRk0XH2h 9ztSOKtb47VAPreaHkVT2fYWXAIwKao61mROet6SyFxN9HsoMrNzaZ1gcm9idN/i QVvO+CbTyTp1N0lu/m7vMDUFmMsVF4O/mAekVUb1Xf8pgR9lRNe1FFguxiVaMiLt YzoZOL/y3EW+H0RVezaQOg2nGc/MLoSdpr/QblzBnpTAw+mjhoojb8E+iumW6iTz N9q+E+5OnHNcKS8n1OHv++0Qu53BnNEoXTIeud9D3w== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvledrvdeikedgvdduucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne cujfgurhepfffhvfevuffkfhggtggujgesghdtreertddtvdenucfhrhhomheprfgrthhr ihgtkhcuufhtvghinhhhrghrughtuceophhssehpkhhsrdhimheqnecuggftrfgrthhtvg hrnhepueektdevtdffveeljeetgfehheeigeekleduvdeffeeghefgledttdehjeelffet necuvehluhhsthgvrhfuihiivgepudenucfrrghrrghmpehmrghilhhfrhhomhepphhsse hpkhhsrdhimh X-ME-Proxy: Feedback-ID: i197146af:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Fri, 24 May 2024 06:04:43 -0400 (EDT) Received: by localhost (OpenSMTPD) with ESMTPSA id 43781825 (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO); Fri, 24 May 2024 10:04:40 +0000 (UTC) Date: Fri, 24 May 2024 12:04:41 +0200 From: Patrick Steinhardt To: git@vger.kernel.org Cc: Eric Sunshine , Junio C Hamano Subject: [PATCH v2 19/21] builtin/mv duplicate string list memory Message-ID: 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: makes the next patch easier, where we will migrate to the paths being owned by a strvec. given that we are talking about command line parameters here it's also not like we have tons of allocations that this would save while at it, fix a memory leak Signed-off-by: Patrick Steinhardt --- builtin/mv.c | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/builtin/mv.c b/builtin/mv.c index 9f4c75df04..12dcc0b13c 100644 --- a/builtin/mv.c +++ b/builtin/mv.c @@ -183,11 +183,12 @@ int cmd_mv(int argc, const char **argv, const char *prefix) struct strbuf a_src_dir = STRBUF_INIT; enum update_mode *modes, dst_mode = 0; struct stat st, dest_st; - struct string_list src_for_dst = STRING_LIST_INIT_NODUP; + struct string_list src_for_dst = STRING_LIST_INIT_DUP; struct lock_file lock_file = LOCK_INIT; struct cache_entry *ce; - struct string_list only_match_skip_worktree = STRING_LIST_INIT_NODUP; - struct string_list dirty_paths = STRING_LIST_INIT_NODUP; + struct string_list only_match_skip_worktree = STRING_LIST_INIT_DUP; + struct string_list dirty_paths = STRING_LIST_INIT_DUP; + int ret; git_config(git_default_config, NULL); @@ -440,8 +441,10 @@ int cmd_mv(int argc, const char **argv, const char *prefix) if (only_match_skip_worktree.nr) { advise_on_updating_sparse_paths(&only_match_skip_worktree); - if (!ignore_errors) - return 1; + if (!ignore_errors) { + ret = 1; + goto out; + } } for (i = 0; i < argc; i++) { @@ -566,12 +569,16 @@ int cmd_mv(int argc, const char **argv, const char *prefix) COMMIT_LOCK | SKIP_IF_UNCHANGED)) die(_("Unable to write new index file")); + ret = 0; + +out: free(dst_w_slash); string_list_clear(&src_for_dst, 0); string_list_clear(&dirty_paths, 0); + string_list_clear(&only_match_skip_worktree, 0); UNLEAK(source); UNLEAK(dest_path); free(submodule_gitfile); free(modes); - return 0; + return ret; }