libmultipath: do not access dm structures after dm_task_destroy
authorHannes Reinecke <hare@suse.de>
Thu, 17 Feb 2011 08:05:57 +0000 (09:05 +0100)
committerHannes Reinecke <hare@suse.de>
Wed, 4 May 2011 07:15:39 +0000 (09:15 +0200)
device-mapper has the habit of freeing up all internal structures
after dm_task_destroy. So we shouldn't try to access any of these
later on.

References: bnc#672857

Signed-off-by: Hannes Reinecke <hare@suse.de>
libmultipath/devmapper.c

index 1e09333..9ee8b9e 100644 (file)
@@ -941,9 +941,10 @@ dm_geteventnr (char *name)
 {
        struct dm_task *dmt;
        struct dm_info info;
+       int event = -1;
 
        if (!(dmt = dm_task_create(DM_DEVICE_INFO)))
-               return 0;
+               return -1;
 
        if (!dm_task_set_name(dmt, name))
                goto out;
@@ -953,20 +954,16 @@ dm_geteventnr (char *name)
        if (!dm_task_run(dmt))
                goto out;
 
-       if (!dm_task_get_info(dmt, &info)) {
-               info.event_nr = 0;
+       if (!dm_task_get_info(dmt, &info))
                goto out;
-       }
 
-       if (!info.exists) {
-               info.event_nr = 0;
-               goto out;
-       }
+       if (info.exists)
+               event = info.event_nr;
 
 out:
        dm_task_destroy(dmt);
 
-       return info.event_nr;
+       return event;
 }
 
 char *