[PATCH rtems] dosfs: Fix memory leak on failed mounts.

Sebastian Huber sebastian.huber at embedded-brains.de
Mon Aug 3 13:57:14 UTC 2020


On 03/08/2020 15:16, Christian Mauderer wrote:

> diff --git a/cpukit/libfs/src/dosfs/msdos_init.c b/cpukit/libfs/src/dosfs/msdos_init.c
> index dc9c76437d..0649258fa7 100644
> --- a/cpukit/libfs/src/dosfs/msdos_init.c
> +++ b/cpukit/libfs/src/dosfs/msdos_init.c
> @@ -102,10 +102,12 @@ int rtems_dosfs_initialize(
>       int                                rc = 0;
>       const rtems_dosfs_mount_options   *mount_options = data;
>       rtems_dosfs_convert_control       *converter;
> +    bool                               converter_created = false;
>   
>   
>       if (mount_options == NULL || mount_options->converter == NULL) {
>           converter = rtems_dosfs_create_default_converter();
> +        converter_created = true;
>       } else {
>           converter = mount_options->converter;
>       }
> @@ -116,6 +118,9 @@ int rtems_dosfs_initialize(
>                                         &msdos_file_handlers,
>                                         &msdos_dir_handlers,
>                                         converter);
> +        if (rc != 0 && converter_created) {
> +            converter->handler->destroy(converter);
> +        }
>       } else {
>           errno = ENOMEM;
>           rc = -1;
Why can't we destroy the converter in both cases?


More information about the devel mailing list