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

Gedare Bloom gedare at rtems.org
Mon Mar 15 20:10:17 UTC 2021


On Fri, Mar 12, 2021 at 8:18 AM Ryan Long <ryan.long at oarcorp.com> 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 (&nvd->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 at rtems.org
> http://lists.rtems.org/mailman/listinfo/devel


More information about the devel mailing list