Received: by 2002:ab2:6309:0:b0:1fb:d597:ff75 with SMTP id s9csp806657lqt; Thu, 6 Jun 2024 21:29:06 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCXSvH12/n693TiL16BrRJlIkQuhtBzm5HG95PQ2i8Y8ElfoI/v/6a5DhoUOQNoPGNCmfmwTyBNax43IAq3KmtURQ4MHEcHa2QOxucCYfA== X-Google-Smtp-Source: AGHT+IFY9V09wW7HAL5CaAnok//WwA5r0/9/vi7bLuEtpKB88YFSFJ/2bw5abgB9TCH+KCi+dNuD X-Received: by 2002:a05:622a:1441:b0:434:7c49:a94e with SMTP id d75a77b69052e-44041b8bc07mr18950761cf.27.1717734545885; Thu, 06 Jun 2024 21:29:05 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1717734545; cv=pass; d=google.com; s=arc-20160816; b=Y0VU8ZrdXHvxdME1mSjR2BWAay6ZCpOXxvjZjagmLuCHouA6wHXIKE6JnR4jiVVChH 2/PVBF/6GlHt8cQw1+GMWi838lk6pe8CmAXcx3UP6AtpH6oumfQrBR2anENrnfdALRdJ a7HQEiytybakB7dgpg6O17kFXej3rZajyBqzAXuP65DMPOp2ZQHKAARIO7I16l92Topy 1OMvKvG6bAMUd6vEaIzw54g1cDocYD7F+Caz9cqCdCNvQtI4+z04Npzq90JEaf7kSz/W 1N89EtC834+Tqvh2Wzq74F5wz1B8fxEsgm20aGc9nkHAdhfaD0QpPeBH/Gdnr4Fm2x6j jMqQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from; bh=ZT3XG1r8jiNl5J0Mo0tCvRFTEjpBlGMFse7VNgDnk4I=; fh=yXYChwFvQA/NaaLzCC0IJdkW11OhjXgO4DHXzVmnGFw=; b=D+c8KH2kS98Pdhi66jnuJoqrPIFoIdVh3byiNvfoHJ0M6ll6d2ALsqtFriHOIHqtKM EofK/uPVJhihfmSHjfiYDtRspi2DiCzhugS3QMHufWXUlLPs0xVNyqnbGBpeBUBkE9yR NWnKlVm5IVqogIXzC6h8J6FUZWkH1W/bDZR1yZ8qOi8pK858eXXO1hnAoKzUMJVzpUeF hsyns9VWBRdFgZI5c2DfddH0BFkDEPajP7rAT4su3j4B2qcmzFYpF0uX38LOrltmWJGk 6W5YXCkw8RNhzn0oPj6yf390NecB+jsEOmptregDOzeQxOf2t5YyuD8tydkNWTw5bOIm uo5A==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1 spf=pass spfdomain=huawei.com dmarc=pass fromdomain=huawei.com); spf=pass (google.com: domain of linux-kernel+bounces-205291-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-205291-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id d75a77b69052e-44038a6ec4csi32398811cf.123.2024.06.06.21.29.05 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 06 Jun 2024 21:29:05 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-205291-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) client-ip=2604:1380:45d1:ec00::1; Authentication-Results: mx.google.com; arc=pass (i=1 spf=pass spfdomain=huawei.com dmarc=pass fromdomain=huawei.com); spf=pass (google.com: domain of linux-kernel+bounces-205291-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-205291-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id 1CC4A1C22182 for ; Fri, 7 Jun 2024 04:29:05 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 70F3D13E8AF; Fri, 7 Jun 2024 04:26:54 +0000 (UTC) Received: from szxga02-in.huawei.com (szxga02-in.huawei.com [45.249.212.188]) (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 6EFAC13E041 for ; Fri, 7 Jun 2024 04:26:52 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=45.249.212.188 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717734413; cv=none; b=ro6hPdaO3gbRzw3YFNqE+IND5/UCmHJmiN3S5zEfC1OmpY1B3aop1QrnZj7W0FhteseiGgAi5gDoW7lLKdRF8Im/Vr84eKMt/nKzVAkzCj4shImy3jFbrXI8o1sfxVxs0uzKU9PB023cDi+xNmMv1D6QK5FE3NqOAVtO0Apho+g= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717734413; c=relaxed/simple; bh=sU2x5b/EvrBaeXm7hZpVhgo6XKCgm3qdgzglMy43Fmg=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=VMma6dmU0eO0XmAX6+W9CKXLev3W6JPB+9H2G0SlGu4iLEyuYrwRje/01OkUV5uufKqa2vHjW4sUGG8UgHtQ2vstuZ7+JAUnCQazmo2pT79qZgBtuacdd6083zhuxnUiUM3xPLhbBLzOVs/hlf/YE/x/fG40WN8TdJFQAhWuWa8= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=huawei.com; spf=pass smtp.mailfrom=huawei.com; arc=none smtp.client-ip=45.249.212.188 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=huawei.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=huawei.com Received: from mail.maildlp.com (unknown [172.19.88.194]) by szxga02-in.huawei.com (SkyGuard) with ESMTP id 4VwShk3xfrzmXhG; Fri, 7 Jun 2024 12:22:14 +0800 (CST) Received: from kwepemm600013.china.huawei.com (unknown [7.193.23.68]) by mail.maildlp.com (Postfix) with ESMTPS id 6211D1400D5; Fri, 7 Jun 2024 12:26:50 +0800 (CST) Received: from huawei.com (10.175.104.67) by kwepemm600013.china.huawei.com (7.193.23.68) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.1.2507.39; Fri, 7 Jun 2024 12:26:35 +0800 From: Zhihao Cheng To: , , , , , CC: , Subject: [RFC PATCH mtd-utils 012/110] mkfs.ubifs: Fix memleak for 'output' in error paths Date: Fri, 7 Jun 2024 12:24:37 +0800 Message-ID: <20240607042615.2069840-13-chengzhihao1@huawei.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240607042615.2069840-1-chengzhihao1@huawei.com> References: <20240607042615.2069840-1-chengzhihao1@huawei.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain X-ClientProxiedBy: dggems706-chm.china.huawei.com (10.3.19.183) To kwepemm600013.china.huawei.com (7.193.23.68) The 'output' is allocated in get_options(), don't forget to free it in error paths, move 'output' freeing out of close_target(), which simplifies the logic of close_target(). Fixes: 36ec51948e0ec ("Add mkfs.ubifs") Signed-off-by: Zhihao Cheng --- ubifs-utils/mkfs.ubifs/mkfs.ubifs.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/ubifs-utils/mkfs.ubifs/mkfs.ubifs.c b/ubifs-utils/mkfs.ubifs/mkfs.ubifs.c index 949187ea..f66c6a46 100644 --- a/ubifs-utils/mkfs.ubifs/mkfs.ubifs.c +++ b/ubifs-utils/mkfs.ubifs/mkfs.ubifs.c @@ -2898,8 +2898,6 @@ static int close_target(void) if (close(out_fd) == -1) return sys_errmsg("cannot close the target '%s'", output); } - if (output) - free(output); return 0; } @@ -3096,6 +3094,7 @@ int main(int argc, char *argv[]) printf("Success!\n"); out: + free(output); close_ubi(); crypto_cleanup(); return err; -- 2.13.6