@@ -418,12 +418,13 @@ out:
return 1;
}
-static int
+static void
factorize_hwtable (vector hw, int n)
{
struct hwentry *hwe1, *hwe2;
int i, j;
+restart:
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);
- 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 *
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 | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-)