block: mount_device: err log only when mp deviates from spec
authorYousong Zhou <yszhou4tech@gmail.com>
Tue, 29 Oct 2019 12:39:50 +0000 (12:39 +0000)
committerJohn Crispin <john@phrozen.org>
Sat, 2 Nov 2019 18:23:23 +0000 (19:23 +0100)
Fixes possible memleak of mp as well

Resolves FS#1523

Signed-off-by: Yousong Zhou <yszhou4tech@gmail.com>
block.c

diff --git a/block.c b/block.c
index 084e7fc95f076776660232dd9500cb8f4419e116..1972c5092a9b14203de416fe1cb7a7ddad64b326 100644 (file)
--- a/block.c
+++ b/block.c
@@ -1092,10 +1092,14 @@ static int mount_device(struct device *dev, int type)
                return -1;
 
        mp = find_mount_point(pr->dev);
-       if (mp && (type != TYPE_HOTPLUG)) {
-               ULOG_ERR("%s is already mounted on %s\n", pr->dev, mp);
+       if (mp) {
+               if (m && m->type == TYPE_MOUNT && strcmp(m->target, mp)) {
+                       ULOG_ERR("%s is already mounted on %s\n", pr->dev, mp);
+                       err = -1;
+               } else
+                       err = 0;
                free(mp);
-               return -1;
+               return err;
        }
 
        if (type == TYPE_HOTPLUG)