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 |
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; >
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 --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;
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(-)