Message ID | 20230110-vv-coverity-fixes-v1-2-c7ee6c76b200@intel.com (mailing list archive) |
---|---|
State | Accepted |
Commit | 5df0713d707b1544a442e535c14962351b009ca4 |
Headers | show |
Series | cxl: misc coverity and typo fixes | expand |
On Tue, Jan 10, 2023 at 04:09:15PM -0700, Vishal Verma wrote: > Static analysis reports there can be a memory leak in to_csv as an exit > path returns from the function before freeing 'csv'. Since this is the > only errpr path exit point after the allocation, just free() before > returning. > > Fixes: 3d6cd829ec08 ("cxl/region: Use cxl_filter_walk() to gather create-region targets") > Cc: Dan Williams <dan.j.williams@intel.com> > Signed-off-by: Vishal Verma <vishal.l.verma@intel.com> Reviewed-by: Alison Schofield <alison.schofield@intel.com> > --- > cxl/region.c | 4 +++- > 1 file changed, 3 insertions(+), 1 deletion(-) > > diff --git a/cxl/region.c b/cxl/region.c > index bb3a10a..9a81113 100644 > --- a/cxl/region.c > +++ b/cxl/region.c > @@ -146,8 +146,10 @@ static const char *to_csv(int *count, const char **strings) > return NULL; > for (i = 0; i < *count; i++) { > list = strdup(strings[i]); > - if (!list) > + if (!list) { > + free(csv); > return NULL; > + } > > for (arg = strtok_r(list, which_sep(list), &save); arg; > arg = strtok_r(NULL, which_sep(list), &save)) { > > -- > 2.39.0
diff --git a/cxl/region.c b/cxl/region.c index bb3a10a..9a81113 100644 --- a/cxl/region.c +++ b/cxl/region.c @@ -146,8 +146,10 @@ static const char *to_csv(int *count, const char **strings) return NULL; for (i = 0; i < *count; i++) { list = strdup(strings[i]); - if (!list) + if (!list) { + free(csv); return NULL; + } for (arg = strtok_r(list, which_sep(list), &save); arg; arg = strtok_r(NULL, which_sep(list), &save)) {
Static analysis reports there can be a memory leak in to_csv as an exit path returns from the function before freeing 'csv'. Since this is the only errpr path exit point after the allocation, just free() before returning. Fixes: 3d6cd829ec08 ("cxl/region: Use cxl_filter_walk() to gather create-region targets") Cc: Dan Williams <dan.j.williams@intel.com> Signed-off-by: Vishal Verma <vishal.l.verma@intel.com> --- cxl/region.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)