From patchwork Fri Jul 26 12:14:33 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Steinhardt X-Patchwork-Id: 13742727 Received: from fhigh1-smtp.messagingengine.com (fhigh1-smtp.messagingengine.com [103.168.172.152]) (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 87483A3D for ; Fri, 26 Jul 2024 12:14:47 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=103.168.172.152 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1721996089; cv=none; b=r7TJcItxUXa9nARBdmhrNOsNFMBNf7uFqYt+FbRF8MW+tCqWbgAwtc39fbVrAVF4hQqc4Uks9FzoOdzsZct6P+oJOyifKowNkMJMP6juNlXG+4Qwz63o41ym0f6nYTSb0DLY4+HqB/NaJF4ErZmZXpPLUFgruFffjnLoTn4PF/I= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1721996089; c=relaxed/simple; bh=xW4OroKUNWqQB0XJvvPX8BCMHn228mjod+yCCtFOPBc=; h=Date:From:To:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=Bahw/IOqDOX1ICwRHiW3Vvg/gDOTMW5s/bHNKCLOCpQuCA4fdSrrbJ+lv/cpD7ukCipUgWbGhw/s8INosw93oaqMoEphOMCI3Dw9mHc5tz9mqELkuqR1UU8nHGrdbOZqaLFf4nFua6N+mI24gYG/TAe+nIA9xvA4CbkOvepeArk= 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=bMWAjoOE; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=CKzmr79f; arc=none smtp.client-ip=103.168.172.152 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="bMWAjoOE"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="CKzmr79f" Received: from compute8.internal (compute8.nyi.internal [10.202.2.227]) by mailfhigh.nyi.internal (Postfix) with ESMTP id A62FC1140284 for ; Fri, 26 Jul 2024 08:14:46 -0400 (EDT) Received: from mailfrontend2 ([10.202.2.163]) by compute8.internal (MEProxy); Fri, 26 Jul 2024 08:14:46 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pks.im; h=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=fm3; t=1721996086; x=1722082486; bh=L9X+j6oqlF 0JPaeEfO1fRYTaDQdPNGkAmU8Y+aRPhFA=; b=bMWAjoOEZSAhX7NrEo6cjpgy/8 TWUWXf0WojZvCzK2Es5VXZCpUVqedERoH5wFUV063/D8dLArX1LLFZ109biqp9Iz ZfysIPKLwaY3N7+Mt7dT2MCaVGmazLIsW2Ii1gfvNaT00EskxuMLSPRcCmUlXSNG IvLrxGk45YxAfWLuHJ6567VfY+EBW+fR8Vdjrs10wpGC/wdyan6BcE3wv7DtLdeI HNf8py+pfnvRwcp433dUggsXGzeNhAJlmJGdyksUadJaNhXjy7r/ZuGdqv7PnehP yS9T6sBw04yxey38dyR1si5c+u87ZfaYs1vzv7hhfjCIdOzmx5wLVR2CkjYA== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=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= fm3; t=1721996086; x=1722082486; bh=L9X+j6oqlF0JPaeEfO1fRYTaDQdP NGkAmU8Y+aRPhFA=; b=CKzmr79f+/nsqKbIhV4Iq8+ejhGLEdVijV+1IwGqX/EY dMf8Swz9Gl/Rg09MpRYskN6bUo+bAe85ZCASOUM8tSB9Jvh+AFNnuQrqHIkS1OLs 1qYYmeHs3teurcqK4J7lRk089PyiYsM1+AcxjFUne0IGhzUTr5soAhJU8xr95Nju lr2pCvP9c2aZ+blvmU/YCol3rCuVyDhKYVzwGXy1nJ0dpYi/e8eNgFTZKfwFmYkV 92ekP2WTFIj7uryxLxHf/HyF6w7iOo5AsaEST1TQfyfov5rtiA2AF6EuV0uo1CU5 ub8eueznqYT10uEA87YIar/+39ZsylgcouifUKaZGA== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeftddrieehgdehtdcutefuodetggdotefrodftvf curfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfghnecu uegrihhlohhuthemuceftddtnecunecujfgurhepfffhvffukfhfgggtuggjsehgtderre dttddvnecuhfhrohhmpefrrghtrhhitghkucfuthgvihhnhhgrrhguthcuoehpshesphhk shdrihhmqeenucggtffrrghtthgvrhhnpeehgefhtdefueffheekgfffudelffejtdfhvd ejkedthfehvdelgfetgfdvtedthfenucevlhhushhtvghrufhiiigvpedtnecurfgrrhgr mhepmhgrihhlfhhrohhmpehpshesphhkshdrihhmpdhnsggprhgtphhtthhopedt X-ME-Proxy: Feedback-ID: i197146af:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA for ; Fri, 26 Jul 2024 08:14:45 -0400 (EDT) Received: by localhost (OpenSMTPD) with ESMTPSA id f805cf68 (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO) for ; Fri, 26 Jul 2024 12:13:22 +0000 (UTC) Date: Fri, 26 Jul 2024 14:14:33 +0200 From: Patrick Steinhardt To: git@vger.kernel.org Subject: [PATCH 04/23] builtin/describe: fix leaking array when running diff-index 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: When running git-describe(1) with `--dirty`, we will set up a `struct rev_info` with arguments for git-diff-index(1). The way we assmble the arguments it causes two memory leaks though: - We never release the `struct strvec`. - `setup_revisions()` may end up removing some entries from the `strvec`, which we wouldn't free even if we released the struct. While we could plug those leaks, this is ultimately unnecessary as the arguments we pass are part of a static array anyway. So instead, refactor the code to drop the `struct strvec` and just pass this static array directly. Signed-off-by: Patrick Steinhardt --- builtin/describe.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/builtin/describe.c b/builtin/describe.c index 4c0980c675..3b61aa1baa 100644 --- a/builtin/describe.c +++ b/builtin/describe.c @@ -695,7 +695,6 @@ int cmd_describe(int argc, const char **argv, const char *prefix) } else if (dirty) { struct lock_file index_lock = LOCK_INIT; struct rev_info revs; - struct strvec args = STRVEC_INIT; int fd; setup_work_tree(); @@ -710,8 +709,9 @@ int cmd_describe(int argc, const char **argv, const char *prefix) repo_update_index_if_able(the_repository, &index_lock); repo_init_revisions(the_repository, &revs, prefix); - strvec_pushv(&args, diff_index_args); - if (setup_revisions(args.nr, args.v, &revs, NULL) != 1) + + if (setup_revisions(ARRAY_SIZE(diff_index_args) - 1, + diff_index_args, &revs, NULL) != 1) BUG("malformed internal diff-index command line"); run_diff_index(&revs, 0);