Message ID | 7ae72048-0c26-9da2-41a9-c1b63a8db117@huawei.com (mailing list archive) |
---|---|
State | New, archived |
Headers | show |
Series | fix serverl issues reported by Coverity | expand |
Zhiqiang Liu <liuzhiqiang26@huawei.com> writes: > In add_dax_region(), region->devname is allocated by > calling strdup(), which may return NULL. So, we need > to check whether region->devname is NULL, and free > region->devname in err_read tag. > > Signed-off-by: Zhiqiang Liu <liuzhiqiang26@huawei.com> > --- > daxctl/lib/libdaxctl.c | 3 +++ > 1 file changed, 3 insertions(+) > > diff --git a/daxctl/lib/libdaxctl.c b/daxctl/lib/libdaxctl.c > index ee4a069..d841b78 100644 > --- a/daxctl/lib/libdaxctl.c > +++ b/daxctl/lib/libdaxctl.c > @@ -287,6 +287,8 @@ static struct daxctl_region *add_dax_region(void *parent, int id, > region->refcount = 1; > list_head_init(®ion->devices); > region->devname = strdup(devpath_to_devname(base)); > + if (!region->devname) > + goto err_read; > > sprintf(path, "%s/%s/size", base, attrs); > if (sysfs_read_attr(ctx, path, buf) == 0) > @@ -314,6 +316,7 @@ static struct daxctl_region *add_dax_region(void *parent, int id, > err_read: > free(region->region_buf); > free(region->region_path); > + free(region->devname); > free(region); > err_region: > free(path); Acked-by: Jeff Moyer <jmoyer@redhat.com>
diff --git a/daxctl/lib/libdaxctl.c b/daxctl/lib/libdaxctl.c index ee4a069..d841b78 100644 --- a/daxctl/lib/libdaxctl.c +++ b/daxctl/lib/libdaxctl.c @@ -287,6 +287,8 @@ static struct daxctl_region *add_dax_region(void *parent, int id, region->refcount = 1; list_head_init(®ion->devices); region->devname = strdup(devpath_to_devname(base)); + if (!region->devname) + goto err_read; sprintf(path, "%s/%s/size", base, attrs); if (sysfs_read_attr(ctx, path, buf) == 0) @@ -314,6 +316,7 @@ static struct daxctl_region *add_dax_region(void *parent, int id, err_read: free(region->region_buf); free(region->region_path); + free(region->devname); free(region); err_region: free(path);
In add_dax_region(), region->devname is allocated by calling strdup(), which may return NULL. So, we need to check whether region->devname is NULL, and free region->devname in err_read tag. Signed-off-by: Zhiqiang Liu <liuzhiqiang26@huawei.com> --- daxctl/lib/libdaxctl.c | 3 +++ 1 file changed, 3 insertions(+)