From patchwork Wed Jun 5 13:40:49 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jerome Marchand X-Patchwork-Id: 13686981 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) (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 00DA3194AE6 for ; Wed, 5 Jun 2024 13:43:03 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.129.124 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717594985; cv=none; b=ULTYvWf8SfzuGnJhEJNSJ9qj9n81ISPzDJqYUFRAYHWqzF0yUVCdt/INP3lgM2lE3bALJFada7awmUWAc1HLL5zd6HDT8PUwPm7S1ByHSJ2220qWKC8KAuEwQRher68v0NgFtu4AGI7wmwGpl4PIG81w9f4t1WTAbafNs1+JuJ8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717594985; c=relaxed/simple; bh=GhXtEryC61CCkkDU92YZJQn78OmrvY5P2X4BtGkR59g=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=WWBPyaOQxcE+B42lHFTDt95fwoxs+MlPmeat2nilDCTB3U9MP0u2AuhQd0B08AaBpkM+wTh3WmLPd4bx8tmJK1l4ci9B+FPecKdX16wxB0OuDdHx7uGheXQunF2H+5QjtaraJ46Yn8Y/yTPiWYGFh3DoiVm8XIkjTyd27jh3zAk= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=ZUMkSlGm; arc=none smtp.client-ip=170.10.129.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="ZUMkSlGm" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1717594983; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=SAZB7cnHFODqMtTyoJ2Qs+FqL4Vc0PY8arBpGJhp0TE=; b=ZUMkSlGm7MQCjib5WPOQNePbtUeirrDOoLC456RROJT7YZThkwuJzFnksY37jNrvxWVpLh hsqutOkrv/mTeWnw+np3FiLgAWdFfxG5Yhf+B+xlQRUrI1tITYs2zxX9uQ/jc6KFHZlvn2 9SwwrzWN+NSpbM5pIpD6W8Hr0zCV9M0= Received: from mx-prod-mc-01.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-427-AvOchIw5PTi97jT2urUTSw-1; Wed, 05 Jun 2024 09:43:01 -0400 X-MC-Unique: AvOchIw5PTi97jT2urUTSw-1 Received: from mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.4]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 00621195DBB1; Wed, 5 Jun 2024 13:43:01 +0000 (UTC) Received: from fedora (unknown [10.45.225.116]) by mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with SMTP id A4196300061F; Wed, 5 Jun 2024 13:42:58 +0000 (UTC) Received: by fedora (sSMTP sendmail emulation); Wed, 05 Jun 2024 15:42:57 +0200 From: "Jerome Marchand" To: Linux Trace Devel Cc: Steven Rostedt , Jerome Marchand Subject: [PATCH 34/38] trace-cmd mem: prevent a memory leak in trace_mem() Date: Wed, 5 Jun 2024 15:40:49 +0200 Message-ID: <20240605134054.2626953-35-jmarchan@redhat.com> In-Reply-To: <20240605134054.2626953-1-jmarchan@redhat.com> References: <20240605134054.2626953-1-jmarchan@redhat.com> Precedence: bulk X-Mailing-List: linux-trace-devel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.4 Close the tracecmd handle in the error path. Fixes a RESOURCE_LEAK error (CWE-772) Signed-off-by: Jerome Marchand --- tracecmd/trace-mem.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tracecmd/trace-mem.c b/tracecmd/trace-mem.c index 3e1ac9f3..6182b096 100644 --- a/tracecmd/trace-mem.c +++ b/tracecmd/trace-mem.c @@ -555,9 +555,10 @@ void trace_mem(int argc, char **argv) ret = tracecmd_read_headers(handle, 0); if (ret) - return; + goto out; do_trace_mem(handle); +out: tracecmd_close(handle); }