Changeset 87fdb20 in rtems


Ignore:
Timestamp:
Aug 3, 2020, 12:18:33 PM (7 weeks ago)
Author:
Christian Mauderer <christian.mauderer@…>
Branches:
master
Children:
2ae557eb
Parents:
6014fad
git-author:
Christian Mauderer <christian.mauderer@…> (08/03/20 12:18:33)
git-committer:
Christian Mauderer <christian.mauderer@…> (08/04/20 06:24:17)
Message:

dosfs: Fix memory leak on failed mounts.

Currently if mount fails, a converter isn't destroyed. We have to take
care of two cases:

  1. The user doesn't provide a converter.

In this case mounting a dosfs creates a default converter. This patch
makes sure that the converter is destroyed again if mount failes for
this case.

  1. The user provides a converter.

In this case it's not sure that the dosfs specific routines are reached
because mount can fail before that. Therefore the user has to destroy
the converter himself again. This patch adds a documentation for that
and implements it in the media server.

Closes #4042.

Location:
cpukit
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • cpukit/include/rtems/dosfs.h

    r6014fad r87fdb20  
    214214  /**
    215215   * @brief Converter implementation for new file system instance.
     216   *
     217   * Note: If you pass a converter to mount, you have to destroy it yourself if
     218   * mount failed. In a good case it is destroyed at unmount.
    216219   *
    217220   * Before converters have been added to the RTEMS implementation of the FAT
     
    271274   *       &mount_opts
    272275   *     );
     276   *
     277   *     if (rv != 0) {
     278   *       (*mount_opts.converter->handler->destroy)(mount_opts.converter);
     279   *     }
    273280   *   } else {
    274281   *     rv = -1;
  • cpukit/libblock/src/media.c

    r6014fad r87fdb20  
    509509      rmdir(mount_path);
    510510      free(mount_path);
     511      (*mount_options.converter->handler->destroy)(mount_options.converter);
    511512
    512513      return RTEMS_IO_ERROR;
  • cpukit/libfs/src/dosfs/msdos_init.c

    r6014fad r87fdb20  
    104104    const rtems_dosfs_mount_options   *mount_options = data;
    105105    rtems_dosfs_convert_control       *converter;
     106    bool                               converter_created = false;
    106107
    107108
    108109    if (mount_options == NULL || mount_options->converter == NULL) {
    109110        converter = rtems_dosfs_create_default_converter();
     111        converter_created = true;
    110112    } else {
    111113        converter = mount_options->converter;
     
    118120                                      &msdos_dir_handlers,
    119121                                      converter);
     122        if (rc != 0 && converter_created) {
     123            (*converter->handler->destroy)(converter);
     124        }
    120125    } else {
    121126        errno = ENOMEM;
Note: See TracChangeset for help on using the changeset viewer.