]> git.ipfire.org Git - thirdparty/mdadm.git/blobdiff - util.c
Fix memory leak in monitor mode
[thirdparty/mdadm.git] / util.c
diff --git a/util.c b/util.c
index 5b994d6ae726b64d4a46046a6c8bac8c8e070f1d..d54d4452c858543f7a17ebf8b8635fe99a8dba91 100644 (file)
--- a/util.c
+++ b/util.c
@@ -416,10 +416,23 @@ char *map_dev(int major, int minor, int create)
        struct devmap *p;
        char *std = NULL, *nonstd=NULL;
        int did_check = 0;
+
+       if (major == 0 && minor == 0) {
+               if (!create)
+                       return NULL;
+               else
+                       return "0:0";
+       }
  retry:
        if (!devlist_ready) {
                char *dev = "/dev";
                struct stat stb;
+               while(devlist) {
+                       struct devmap *d = devlist;
+                       devlist = d->next;
+                       free(d->name);
+                       free(d);
+               }
                if (lstat(dev, &stb)==0 &&
                    S_ISLNK(stb.st_mode))
                        dev = "/dev/.";