]> sourceware.org Git - lvm2.git/commitdiff
device_id: fix memleak and free idname
authorZdenek Kabelac <zkabelac@redhat.com>
Thu, 22 Apr 2021 22:25:14 +0000 (00:25 +0200)
committerZdenek Kabelac <zkabelac@redhat.com>
Fri, 23 Apr 2021 20:57:08 +0000 (22:57 +0200)
Remove extra code path used only for 'free()'
and free(idname) on all paths that do not add it to list
and avoid memleak in few cases.

lib/device/device_id.c

index cf5867dabcb8e01dd7fcdd75e2b62dc7beaebd03..1a9705f0430ac7c1f809b6bc4fe38c838ea0285a 100644 (file)
@@ -1008,21 +1008,24 @@ id_done:
                        break;
                }
        }
-       if (found_id && !strcmp(id->idname, idname)) {
-               free((char *)idname);
-       } else if (found_id && strcmp(id->idname, idname)) {
+
+       if (found_id && idname && strcmp(id->idname, idname)) {
                dm_list_del(&id->list);
                free_did(id);
                found_id = 0;
        }
        if (!found_id) {
-               if (!(id = zalloc(sizeof(struct dev_id))))
+               if (!(id = zalloc(sizeof(struct dev_id)))) {
+                       free((char *)idname);
                        return_0;
+               }
                id->idtype = idtype;
                id->idname = (char *)idname;
                id->dev = dev;
                dm_list_add(&dev->ids, &id->list);
-       }
+       } else
+               free((char*)idname);
+
        dev->id = id;
        dev->flags |= DEV_MATCHED_USE_ID;
 
This page took 0.045471 seconds and 5 git commands to generate.