[PATCH 16/16] fs mount: fix error handling
Sascha Hauer
s.hauer at pengutronix.de
Fri Apr 8 10:37:02 EDT 2011
If we register a device we have to unregister it later when
the driver did not accept the device. Also, do not forget to
free the backingstore string.
Signed-off-by: Sascha Hauer <s.hauer at pengutronix.de>
---
fs/fs.c | 19 +++++++++++++------
1 files changed, 13 insertions(+), 6 deletions(-)
diff --git a/fs/fs.c b/fs/fs.c
index 8f43481..e71d5a2 100644
--- a/fs/fs.c
+++ b/fs/fs.c
@@ -780,8 +780,7 @@ int mount(const char *device, const char *fsname, const char *_path)
if (!device) {
printf("need a device for driver %s\n", fsname);
errno = -ENODEV;
- free(fsdev);
- goto out;
+ goto out1;
}
}
safe_strncpy(fsdev->dev.name, fsname, MAX_DRIVER_NAME);
@@ -789,16 +788,14 @@ int mount(const char *device, const char *fsname, const char *_path)
fsdev->dev.id = get_free_deviceid(fsdev->dev.name);
if ((ret = register_device(&fsdev->dev))) {
- free(fsdev);
errno = ret;
- goto out;
+ goto out1;
}
if (!fsdev->dev.driver) {
/* driver didn't accept the device. Bail out */
- free(fsdev);
errno = -EINVAL;
- goto out;
+ goto out2;
}
if (parent_device)
@@ -822,6 +819,16 @@ int mount(const char *device, const char *fsname, const char *_path)
e->next = entry;
}
errno = 0;
+
+ free(path);
+ return 0;
+
+out2:
+ unregister_device(&fsdev->dev);
+out1:
+ if (fsdev->backingstore)
+ free(fsdev->backingstore);
+ free(fsdev);
out:
free(path);
return errno;
--
1.7.2.3
More information about the barebox
mailing list