Re: [PATCH 3/5] nvdisk.c: Fix Resource leak (CID #1439297)

2021-03-15 Thread Gedare Bloom
On Mon, Mar 15, 2021 at 2:28 PM Joel Sherrill  wrote:
>
>
>
> On Mon, Mar 15, 2021, 3:10 PM Gedare Bloom  wrote:
>>
>> On Fri, Mar 12, 2021 at 8:18 AM Ryan Long  wrote:
>> >
>> > CID 1439297: Resource leak in rtems_nvdisk_initialize().
>> >
>> > Closes #4298
>> > ---
>> >  cpukit/libblock/src/nvdisk.c | 8 +++-
>> >  1 file changed, 7 insertions(+), 1 deletion(-)
>> >
>> > diff --git a/cpukit/libblock/src/nvdisk.c b/cpukit/libblock/src/nvdisk.c
>> > index a7f4167..d742baf 100644
>> > --- a/cpukit/libblock/src/nvdisk.c
>> > +++ b/cpukit/libblock/src/nvdisk.c
>> > @@ -766,8 +766,10 @@ rtems_nvdisk_initialize (rtems_device_major_number 
>> > major RTEMS_UNUSED,
>> >  nvd->info_level   = c->info_level;
>> >
>> >  nvd->devices = calloc (c->device_count, sizeof 
>> > (rtems_nvdisk_device_ctl));
>> > -if (!nvd->devices)
>> > +if (!nvd->devices) {
>> > +  free(nvd);
>> >return RTEMS_NO_MEMORY;
>> > +}
>> >
>> >  for (device = 0; device < c->device_count; device++)
>> >  {
>> > @@ -790,6 +792,8 @@ rtems_nvdisk_initialize (rtems_device_major_number 
>> > major RTEMS_UNUSED,
>> >   rtems_nvdisk_ioctl, nvd);
>> >  if (sc != RTEMS_SUCCESSFUL)
>> >  {
>> > +  free(nvd->devices);
>> > +  free(nvd);
>> >rtems_nvdisk_error ("disk create phy failed");
>> >return sc;
>> >  }
>> > @@ -797,5 +801,7 @@ rtems_nvdisk_initialize (rtems_device_major_number 
>> > major RTEMS_UNUSED,
>> >  rtems_mutex_init (>lock, "NV Disk");
>> >}
>> >
>> > +  free(nvd->devices);
>> > +  free(nvd);
>>
>> Does the rtems_blkdev_create() link the nvd? (I think the answer is
>> yes.) Then, this is not correct.
>
>
> I think this is my suggestion so what do you think should happen on this case?

Does the block device driver register a callback handler for the
device_data destruction?

>>
>>
>> >return RTEMS_SUCCESSFUL;
>> >  }
>> > --
>> > 1.8.3.1
>> >
>> > ___
>> > devel mailing list
>> > devel@rtems.org
>> > http://lists.rtems.org/mailman/listinfo/devel
>> ___
>> devel mailing list
>> devel@rtems.org
>> http://lists.rtems.org/mailman/listinfo/devel
___
devel mailing list
devel@rtems.org
http://lists.rtems.org/mailman/listinfo/devel


Re: [PATCH 3/5] nvdisk.c: Fix Resource leak (CID #1439297)

2021-03-15 Thread Joel Sherrill
On Mon, Mar 15, 2021, 3:10 PM Gedare Bloom  wrote:

> On Fri, Mar 12, 2021 at 8:18 AM Ryan Long  wrote:
> >
> > CID 1439297: Resource leak in rtems_nvdisk_initialize().
> >
> > Closes #4298
> > ---
> >  cpukit/libblock/src/nvdisk.c | 8 +++-
> >  1 file changed, 7 insertions(+), 1 deletion(-)
> >
> > diff --git a/cpukit/libblock/src/nvdisk.c b/cpukit/libblock/src/nvdisk.c
> > index a7f4167..d742baf 100644
> > --- a/cpukit/libblock/src/nvdisk.c
> > +++ b/cpukit/libblock/src/nvdisk.c
> > @@ -766,8 +766,10 @@ rtems_nvdisk_initialize (rtems_device_major_number
> major RTEMS_UNUSED,
> >  nvd->info_level   = c->info_level;
> >
> >  nvd->devices = calloc (c->device_count, sizeof
> (rtems_nvdisk_device_ctl));
> > -if (!nvd->devices)
> > +if (!nvd->devices) {
> > +  free(nvd);
> >return RTEMS_NO_MEMORY;
> > +}
> >
> >  for (device = 0; device < c->device_count; device++)
> >  {
> > @@ -790,6 +792,8 @@ rtems_nvdisk_initialize (rtems_device_major_number
> major RTEMS_UNUSED,
> >   rtems_nvdisk_ioctl, nvd);
> >  if (sc != RTEMS_SUCCESSFUL)
> >  {
> > +  free(nvd->devices);
> > +  free(nvd);
> >rtems_nvdisk_error ("disk create phy failed");
> >return sc;
> >  }
> > @@ -797,5 +801,7 @@ rtems_nvdisk_initialize (rtems_device_major_number
> major RTEMS_UNUSED,
> >  rtems_mutex_init (>lock, "NV Disk");
> >}
> >
> > +  free(nvd->devices);
> > +  free(nvd);
>
> Does the rtems_blkdev_create() link the nvd? (I think the answer is
> yes.) Then, this is not correct.
>

I think this is my suggestion so what do you think should happen on this
case?

>
> >return RTEMS_SUCCESSFUL;
> >  }
> > --
> > 1.8.3.1
> >
> > ___
> > devel mailing list
> > devel@rtems.org
> > http://lists.rtems.org/mailman/listinfo/devel
> ___
> devel mailing list
> devel@rtems.org
> http://lists.rtems.org/mailman/listinfo/devel
>
___
devel mailing list
devel@rtems.org
http://lists.rtems.org/mailman/listinfo/devel

Re: [PATCH 3/5] nvdisk.c: Fix Resource leak (CID #1439297)

2021-03-15 Thread Gedare Bloom
On Fri, Mar 12, 2021 at 8:18 AM Ryan Long  wrote:
>
> CID 1439297: Resource leak in rtems_nvdisk_initialize().
>
> Closes #4298
> ---
>  cpukit/libblock/src/nvdisk.c | 8 +++-
>  1 file changed, 7 insertions(+), 1 deletion(-)
>
> diff --git a/cpukit/libblock/src/nvdisk.c b/cpukit/libblock/src/nvdisk.c
> index a7f4167..d742baf 100644
> --- a/cpukit/libblock/src/nvdisk.c
> +++ b/cpukit/libblock/src/nvdisk.c
> @@ -766,8 +766,10 @@ rtems_nvdisk_initialize (rtems_device_major_number major 
> RTEMS_UNUSED,
>  nvd->info_level   = c->info_level;
>
>  nvd->devices = calloc (c->device_count, sizeof 
> (rtems_nvdisk_device_ctl));
> -if (!nvd->devices)
> +if (!nvd->devices) {
> +  free(nvd);
>return RTEMS_NO_MEMORY;
> +}
>
>  for (device = 0; device < c->device_count; device++)
>  {
> @@ -790,6 +792,8 @@ rtems_nvdisk_initialize (rtems_device_major_number major 
> RTEMS_UNUSED,
>   rtems_nvdisk_ioctl, nvd);
>  if (sc != RTEMS_SUCCESSFUL)
>  {
> +  free(nvd->devices);
> +  free(nvd);
>rtems_nvdisk_error ("disk create phy failed");
>return sc;
>  }
> @@ -797,5 +801,7 @@ rtems_nvdisk_initialize (rtems_device_major_number major 
> RTEMS_UNUSED,
>  rtems_mutex_init (>lock, "NV Disk");
>}
>
> +  free(nvd->devices);
> +  free(nvd);

Does the rtems_blkdev_create() link the nvd? (I think the answer is
yes.) Then, this is not correct.

>return RTEMS_SUCCESSFUL;
>  }
> --
> 1.8.3.1
>
> ___
> devel mailing list
> devel@rtems.org
> http://lists.rtems.org/mailman/listinfo/devel
___
devel mailing list
devel@rtems.org
http://lists.rtems.org/mailman/listinfo/devel


[PATCH 3/5] nvdisk.c: Fix Resource leak (CID #1439297)

2021-03-12 Thread Ryan Long
CID 1439297: Resource leak in rtems_nvdisk_initialize().

Closes #4298
---
 cpukit/libblock/src/nvdisk.c | 8 +++-
 1 file changed, 7 insertions(+), 1 deletion(-)

diff --git a/cpukit/libblock/src/nvdisk.c b/cpukit/libblock/src/nvdisk.c
index a7f4167..d742baf 100644
--- a/cpukit/libblock/src/nvdisk.c
+++ b/cpukit/libblock/src/nvdisk.c
@@ -766,8 +766,10 @@ rtems_nvdisk_initialize (rtems_device_major_number major 
RTEMS_UNUSED,
 nvd->info_level   = c->info_level;
 
 nvd->devices = calloc (c->device_count, sizeof (rtems_nvdisk_device_ctl));
-if (!nvd->devices)
+if (!nvd->devices) {
+  free(nvd);
   return RTEMS_NO_MEMORY;
+}
 
 for (device = 0; device < c->device_count; device++)
 {
@@ -790,6 +792,8 @@ rtems_nvdisk_initialize (rtems_device_major_number major 
RTEMS_UNUSED,
  rtems_nvdisk_ioctl, nvd);
 if (sc != RTEMS_SUCCESSFUL)
 {
+  free(nvd->devices);
+  free(nvd);
   rtems_nvdisk_error ("disk create phy failed");
   return sc;
 }
@@ -797,5 +801,7 @@ rtems_nvdisk_initialize (rtems_device_major_number major 
RTEMS_UNUSED,
 rtems_mutex_init (>lock, "NV Disk");
   }
 
+  free(nvd->devices);
+  free(nvd);
   return RTEMS_SUCCESSFUL;
 }
-- 
1.8.3.1

___
devel mailing list
devel@rtems.org
http://lists.rtems.org/mailman/listinfo/devel