On 2/17/23 5:40 PM, Vishal Verma wrote:
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.ji...@intel.com>
Cc: Dan Williams <dan.j.willi...@intel.com>
Signed-off-by: Vishal Verma <vishal.l.ve...@intel.com>

Reviewed-by: Dave Jiang <dave.ji...@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;


Reply via email to