From 87fdb206fa018bd1366434a5535e608eb7f45137 Mon Sep 17 00:00:00 2001 From: Christian Mauderer Date: Mon, 3 Aug 2020 14:18:33 +0200 Subject: 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. 2. 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. --- cpukit/libfs/src/dosfs/msdos_init.c | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'cpukit/libfs/src/dosfs/msdos_init.c') diff --git a/cpukit/libfs/src/dosfs/msdos_init.c b/cpukit/libfs/src/dosfs/msdos_init.c index 3ea6f104e8..2874172484 100644 --- a/cpukit/libfs/src/dosfs/msdos_init.c +++ b/cpukit/libfs/src/dosfs/msdos_init.c @@ -103,10 +103,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; } @@ -117,6 +119,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; -- cgit v1.2.3