From nobody Thu May 23 18:28:33 2024 X-Original-To: dev-commits-src-all@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4VlcB96HDmz5L2cn; Thu, 23 May 2024 18:28:33 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4VlcB94FHzz4wXy; Thu, 23 May 2024 18:28:33 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1716488913; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=p648VWC2+v9BbWWQJAZZVcFQMyXLHGWAHEsMgiVJC7E=; b=uvzad7u78RTEjwgPFO/8jakt/HOvNagG9T4BY9Y65Gf26lES6jIUONncWiZog2yVODI1KR hg2X6VnuGIpq75Y3VmBCp9SpPzNuDm+/qQYL0OCeaPfMeu9mlSC/0MQTxtuAUeXumVeWSh nmEnOevZ+kUqFf3ZhWH/yntOahtdzr0GmQLfYNx4w1LWPR9jsdXD0FFzIjdBgspUyNJ2b1 cVoPENleLmsl0Rug47DM3hoxOGH2y1mQi9dSDiCNJN1FdwkFF2ZMAWcSmYiSS1eWbO8PMe Km5fgl416MGDFCkdo3kKfLbofdGcCCIh5HWwO0V5Iu2aScjXxWvbGU1mY7lAPA== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1716488913; a=rsa-sha256; cv=none; b=fiE9m20hC5mHhZtFrWzo/hULObIwFTW5QwMcugU2FkbGPL+7vQAMuHwtk68Nz0GwuleRkX Jz+nLdgqBS/WfZjWpZ3Ns7OapSwqeVZNDbfkByu+Cl5r5EiTULTJmCzAVLr+wAM0rrAQnF NsPjSi+Om7fiPSNZSm9iXFaNfU4cW69guccPdGYHCABUWy6WNoVuzy3LK7ivVfCgXlrzb2 smRkaSqbUETGrt4UahvIChCTeKQnKnMdwUw04jVxVD9X/KTn5Q2c7wkghmqoffzXj7N9l0 o6Y5FXqGksfkKxA2l7YrEBgPXQ6s++nz0btiRspd659Pp5leHXTB9xh5VopSZA== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1716488913; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=p648VWC2+v9BbWWQJAZZVcFQMyXLHGWAHEsMgiVJC7E=; b=L7gDMMvVAhBlZbaPFHKJp6AL0h/t6RL5qqvzcyqkJSuDSTaBRAEftvKHIvOdzdKXfbm0Io ld+JJnfHSESEGUHr8SlbJF81HeQjT4z8lwLQSHRpZZ9eBCxiR3xqof/VsAdEwaJCJzNBji J0OM+WMCBAtgFhxwi5LKAVqCjdHthiNm3fwE9xkDmHOPVMr156UH/4pxDNl5lNja6Zm7Ur sSkb/No2y2tsjFKuVEfbUsSfvVN63qLxRktEfydhvSax9/InkWjOE3fIrx2hu30VXDLkJl NeTaFefGXUhlPfIqE0x/DxhCccnD8o9vy3EE2pd7ZC17HdsDwGDXmccN2Jb4uA== Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 4VlcB93sG5z11Ff; Thu, 23 May 2024 18:28:33 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.17.1/8.17.1) with ESMTP id 44NISXvH050494; Thu, 23 May 2024 18:28:33 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.17.1/8.17.1/Submit) id 44NISX2W050491; Thu, 23 May 2024 18:28:33 GMT (envelope-from git) Date: Thu, 23 May 2024 18:28:33 GMT Message-Id: <202405231828.44NISX2W050491@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Warner Losh Subject: git: 3d7c8f088796 - main - cp: avoid a resource leak List-Id: Commit messages for all branches of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-all List-Help: List-Post: List-Subscribe: List-Unsubscribe: X-BeenThere: dev-commits-src-all@freebsd.org Sender: owner-dev-commits-src-all@FreeBSD.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: imp X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: 3d7c8f088796ec6ceb1d54005657dee78fd01fbe Auto-Submitted: auto-generated The branch main has been updated by imp: URL: https://cgit.FreeBSD.org/src/commit/?id=3d7c8f088796ec6ceb1d54005657dee78fd01fbe commit 3d7c8f088796ec6ceb1d54005657dee78fd01fbe Author: Pierre Pronchery AuthorDate: 2024-05-16 14:19:44 +0000 Commit: Warner Losh CommitDate: 2024-05-23 18:04:43 +0000 cp: avoid a resource leak In copy_file(), make sure the from_fd file descriptor is closed even when the operation failed early. Reported by: Coverity Scan CID: 1545036 Sponsored by: The FreeBSD Foundation Reviewed by: imp, emaste Pull Request: https://github.com/freebsd/freebsd-src/pull/1238 --- bin/cp/utils.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/bin/cp/utils.c b/bin/cp/utils.c index d102fb076139..cfbb2022caaf 100644 --- a/bin/cp/utils.c +++ b/bin/cp/utils.c @@ -112,6 +112,8 @@ copy_file(const FTSENT *entp, int dne) if ((from_fd = open(entp->fts_path, O_RDONLY, 0)) < 0 || fstat(from_fd, &sb) != 0) { warn("%s", entp->fts_path); + if (from_fd >= 0) + (void)close(from_fd); return (1); } /* @@ -124,6 +126,7 @@ copy_file(const FTSENT *entp, int dne) */ if ((sb.st_mode & S_IFMT) != (fs->st_mode & S_IFMT)) { warnx("%s: File changed", entp->fts_path); + (void)close(from_fd); return (1); } }