diff mbox series

[ndctl,1/3] cxl/event_trace: fix a resource leak in cxl_event_to_json()

Message ID 20230217-coverity-fixes-v1-1-043fac896a40@intel.com
State Accepted
Commit 00bbc7c4af940ec00fa18ae91160b94b62ec8b81
Headers show
Series cxl/monitor: coverity and misc other fixes | expand

Commit Message

Verma, Vishal L Feb. 18, 2023, 12:40 a.m. UTC
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(-)

Comments

Dave Jiang Feb. 21, 2023, 4:44 p.m. UTC | #1
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.jiang@intel.com>
> Cc: Dan Williams <dan.j.williams@intel.com>
> Signed-off-by: Vishal Verma <vishal.l.verma@intel.com>

Reviewed-by: Dave Jiang <dave.jiang@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;
>
Ira Weiny Feb. 22, 2023, 1:53 a.m. UTC | #2
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.jiang@intel.com>
> Cc: Dan Williams <dan.j.williams@intel.com>

Reviewed-by: Ira Weiny <ira.weiny@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
> 
>
diff mbox series

Patch

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;