Received: by 2002:ab2:6857:0:b0:1ef:ffd0:ce49 with SMTP id l23csp1850266lqp; Sat, 23 Mar 2024 11:22:17 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCWuVkSH+8WoexyunE+NMeZEHHfcfREaZmLVPw3+xKrGLhab6Mz2V/jUJXME85hyyxs0yrFTp9dtYUgqfpy/3cTu0qVgrAVuJCv/CXyOFA== X-Google-Smtp-Source: AGHT+IH0njoU5VfbJ0hWItnijTsVkVUHBZ1Fu3HkSi02GeJasXh0fAt86/RntC8mVJyo2qnrjXCI X-Received: by 2002:a05:620a:5cd2:b0:788:1bda:8aa3 with SMTP id xr18-20020a05620a5cd200b007881bda8aa3mr2782265qkn.19.1711218137425; Sat, 23 Mar 2024 11:22:17 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1711218137; cv=pass; d=google.com; s=arc-20160816; b=eu2vDpcLzieUMBBVxp0s4GpUXvXv7a0Jl2x/yBXwuxrzxDWZ7j7qPbxEHZAFY58UXb XOJx5alTxuF4AYe4FPpKKCrJuCT4RQbv5DPzstJijgWr4YLkH8nz3bBM1x24V+kiJyoq 6o7ks1Py2eiBjwdSJLGATgAMeXVEdP4umlRFEptNZ/fsd7GSfzJ0IIq0DQuCUmYWOLIl PI9Srv6etgaJowBAxRHDx7mXQwg2cqXVFss0A9PUEGMbQrrH8Z2icDfbritasJZ9D09X FKeHNEi4sCfV6xzcBV1TfI6nqf3pOR1Mmn3aP2EeMNVyfQ/uzqFY5yKgW9fJ2g09ZG7P CBpw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=in-reply-to:content-disposition:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:message-id:subject:cc :to:from:date:dkim-signature; bh=6yqYru6oO0MtWVWD9c3YuLfMhi+UqEMrEq9GQ4KzJj0=; fh=7PQZsO/2SdegnfL0YbjnGGaupj4+isTaJtxq6WQgAgM=; b=pD4UPgbeCkN7FyIfCMj0o2Z6Hi5WdFV0DTRSsTXH86CO4diMdri2EnLFLjSyWjdsCo RgvXhurXlozNhFwBMEhcPjBtIvNRynXlF65NrJf4+kgg2wQ0e+An9oJDqwrW8NHa3Xlk 9Byd1BLZZ6fod/+GEa4Q7PazOSPWjkAwPhQOZRX4SJVEjGDW6+PzjcOmSueOvJjzH539 glAH43YvW/0bgve/jZQEGwW/1OF3SdrrD9S5o/oSUv6tXYtUl7JMOov2Hj8yVCE6CET7 OugW8LLJURJ1VsL9DYUmCRVgw759dvXl6VNAY6+PysOz/jFqkGrQ6D0o5/1HC1hTvODl kTdg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b="W/sNN4to"; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-112442-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-112442-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id z1-20020ae9e601000000b00789fc9196dcsi2121637qkf.557.2024.03.23.11.22.17 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 23 Mar 2024 11:22:17 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-112442-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) client-ip=147.75.199.223; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b="W/sNN4to"; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-112442-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-112442-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org 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 2A3201C20ACC for ; Sat, 23 Mar 2024 18:22:17 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 9DB1954BFC; Sat, 23 Mar 2024 18:22:12 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="W/sNN4to" Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 C8F0218E20 for ; Sat, 23 Mar 2024 18:22:11 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711218131; cv=none; b=ecSBVYQsw5RUX4QZnH2cxbr7Hn903pmKcMHR6dAsG+0jPwhwl0SNUz7XfFslHVpXV3Sa0MQGh3WogxHMh0tXQAjBFTFEiLZoLCXvaWLll659WC+siPmycfiYbmYxy/4Ah6byHeupPT3r36is9JyMoHbf1KFnejGvr40wLD1fr+Q= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711218131; c=relaxed/simple; bh=qEKaqECtaD+QVRVzEOmQc7FxWOj+XhOPB3xcovL758A=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=f7WJZkx6RefpEzrkG2NlTTGKyQNC4nM/2fBoKfPThaYjfeJiM5PmKptrRaVOFLU5T+Hn/LIXHBJHNsvRSQYA5biIqbfwG8ltvga4DFdUGWOkVsnAQgB5QUFs3wZ9YH/O9fHmvECTai9QNNkT4BAJY0r/KGn+7a+vNZSe8qaZbto= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=W/sNN4to; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 45DFDC433C7; Sat, 23 Mar 2024 18:22:11 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1711218131; bh=qEKaqECtaD+QVRVzEOmQc7FxWOj+XhOPB3xcovL758A=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=W/sNN4toO4QK8xqsuogZFCFrBC506WXgAURAqKIfvTw1GhgChNwNundMlEUL/Zkvg 89INL+YK3fwOFOps2k+TwbLZjQmG3Ky+0O8ucRKHfMnDYA360QdlKyJf6X7iHB6TK3 OVFJXA3rGIBxeEkO2FHNGnE8+fMBtvn3n58j4ogcSHyRMHbKcmoVpQ4AGKFOk6ho5D YUKtUqFUOMI6K1oCap8k5poU8hPVNdfDuNYKsCJYyymX5VOEzl0DqaNVmqDKaaUj6u FKEtppGq3CX1FOZtZrUeomctNt8EFlMK1Tvf4dIkykhRRX9FgKJoviAOYp7G+9kofG l8no1Ac7Opo7w== Date: Sat, 23 Mar 2024 11:22:09 -0700 From: Josh Poimboeuf To: LuMingYin Cc: linux-kernel@vger.kernel.org, peterz@infradead.org Subject: Re: [PATCH] tools:Fix a memory leak related to variable name Message-ID: <20240323182209.xqzb6rsswvfbg74n@treble> References: <20240323084526.662556-1-lumingyindetect@163.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: <20240323084526.662556-1-lumingyindetect@163.com> On Sat, Mar 23, 2024 at 04:45:26PM +0800, LuMingYin wrote: > In the elf_create_prefix_symbol function defined in the /linux/tools/objtool/elf.c file, two pointer variables sym and name are defined. The program allocates dynamic memory for the pointer sym using the calloc function at line 822, and for the pointer name using the malloc function at line 824. When the if statement at line 826 returns true, the program returns at line 828. The content of the if statement at line 828 is if (sym==NULL || name==NULL), which checks if either sym or name is NULL. If this condition returns true, it indicates a situation where one of the pointers has successfully allocated memory but the other has not. Therefore, if the if statement returns true, directly returning may lead to memory leak issues. Hence, in the code, I have added checks separately for whether sym and name are NULL, and if they are not NULL, the corresponding dynamic memory spaces are freed. > > Signed-off-by: LuMingYin Thanks for the patch. In general we don't care about memory leaks in objtool (particularly in error or exit paths), as it's a short-running tool. When it exits, all the memory will be freed anyway. So it's faster to not free the memory manually. -- Josh