Break out loop in factorize_hwtable()
authorHannes Reinecke <hare@suse.de>
Thu, 17 Jan 2013 14:59:28 +0000 (15:59 +0100)
committerChristophe Varoqui <christophe.varoqui@opensvc.com>
Fri, 18 Jan 2013 19:04:03 +0000 (20:04 +0100)
We need to break out of the loop in factorize_hwtable() as
soon as we have removed a duplicate. Otherwise we might run
onto an deleted element in the outer loop.
Also we should declare factorize_hwtable() as 'void'
as it doesn't return anything.

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

index 2d88226..25d3e3d 100644 (file)
@@ -418,12 +418,13 @@ out:
        return 1;
 }
 
        return 1;
 }
 
-static int
+static void
 factorize_hwtable (vector hw, int n)
 {
        struct hwentry *hwe1, *hwe2;
        int i, j;
 
 factorize_hwtable (vector hw, int n)
 {
        struct hwentry *hwe1, *hwe2;
        int i, j;
 
+restart:
        vector_foreach_slot(hw, hwe1, i) {
                if (i == n)
                        break;
        vector_foreach_slot(hw, hwe1, i) {
                if (i == n)
                        break;
@@ -435,14 +436,17 @@ factorize_hwtable (vector hw, int n)
                        merge_hwe(hwe2, hwe1);
                        if (hwe_strmatch(hwe2, hwe1) == 0) {
                                vector_del_slot(hw, i);
                        merge_hwe(hwe2, hwe1);
                        if (hwe_strmatch(hwe2, hwe1) == 0) {
                                vector_del_slot(hw, i);
-                               free_hwe(hwe1);
-                               n -= 1;
-                               i -= 1;
-                               break;
+                               /*
+                                * Play safe here; we have modified
+                                * the original vector so the outer
+                                * vector_foreach_slot() might
+                                * become confused.
+                                */
+                               goto restart;
                        }
                }
        }
                        }
                }
        }
-       return 0;
+       return;
 }
 
 struct config *
 }
 
 struct config *