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 <[email protected]>
> Cc: Dan Williams <[email protected]>
Reviewed-by: Ira Weiny <[email protected]>
> Signed-off-by: Vishal Verma <[email protected]>
> ---
> 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
>
>