Linux CXL
 help / color / mirror / Atom feed
From: Vishal Verma <vishal.l.verma@intel.com>
To: linux-cxl@vger.kernel.org
Cc: nvdimm@lists.linux.dev, Dave Jiang <dave.jiang@intel.com>,
	Dan Williams <dan.j.williams@intel.com>,
	Vishal Verma <vishal.l.verma@intel.com>
Subject: [PATCH ndctl 1/3] cxl/event_trace: fix a resource leak in cxl_event_to_json()
Date: Fri, 17 Feb 2023 17:40:22 -0700	[thread overview]
Message-ID: <20230217-coverity-fixes-v1-1-043fac896a40@intel.com> (raw)
In-Reply-To: <20230217-coverity-fixes-v1-0-043fac896a40@intel.com>

Static analysis reports that a 'return -ENOMEM' in the above function
bypasses the error unwinding and leaks 'jevent'.

Fix the error handling to use the right goto sequence before returning.

Fixes: 8dedc6cf5e85 ("cxl: add a helper to parse trace events into a json object")
Cc: Dave Jiang <dave.jiang@intel.com>
Cc: Dan Williams <dan.j.williams@intel.com>
Signed-off-by: Vishal Verma <vishal.l.verma@intel.com>
---
 cxl/event_trace.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/cxl/event_trace.c b/cxl/event_trace.c
index a973a1f..76dd4e7 100644
--- a/cxl/event_trace.c
+++ b/cxl/event_trace.c
@@ -142,7 +142,8 @@ static int cxl_event_to_json(struct tep_event *event, struct tep_record *record,
 				jobj = num_to_json(data, f->elementsize, f->flags);
 				if (!jobj) {
 					json_object_put(jarray);
-					return -ENOMEM;
+					rc = -ENOMEM;
+					goto err_jevent;
 				}
 				json_object_array_add(jarray, jobj);
 				data += f->elementsize;

-- 
2.39.1


  reply	other threads:[~2023-02-18  0:44 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-02-18  0:40 [PATCH ndctl 0/3] cxl/monitor: coverity and misc other fixes Vishal Verma
2023-02-18  0:40 ` Vishal Verma [this message]
2023-02-21 16:44   ` [PATCH ndctl 1/3] cxl/event_trace: fix a resource leak in cxl_event_to_json() Dave Jiang
2023-02-22  1:53   ` Ira Weiny
2023-02-18  0:40 ` [PATCH ndctl 2/3] cxl/monitor: retain error code in monitor_event() Vishal Verma
2023-02-21 16:45   ` Dave Jiang
2023-02-22  1:56   ` Ira Weiny
2023-02-22  6:33     ` Verma, Vishal L
2023-02-18  0:40 ` [PATCH ndctl 3/3] test/cxl-security.sh: avoid intermittent failures due to sasync probe Vishal Verma
2023-02-21 16:45   ` Dave Jiang
2023-02-21 17:22   ` Alison Schofield
2023-02-21 18:08     ` Dan Williams
2023-02-21 18:13     ` Verma, Vishal L
2023-02-21 18:34       ` Alison Schofield

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20230217-coverity-fixes-v1-1-043fac896a40@intel.com \
    --to=vishal.l.verma@intel.com \
    --cc=dan.j.williams@intel.com \
    --cc=dave.jiang@intel.com \
    --cc=linux-cxl@vger.kernel.org \
    --cc=nvdimm@lists.linux.dev \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox