int test, struct alert_info *info);
static void try_spare_migration(struct state *statelist, struct alert_info *info);
static void link_containers_with_subarrays(struct state *list);
+static void free_statelist(struct state *statelist);
#ifndef NO_LIBUDEV
static int check_udev_activity(void);
#endif
*/
struct state *statelist = NULL;
- struct state *st2;
int finished = 0;
struct mdstat_ent *mdstat = NULL;
char *mailfrom;
continue;
if (strcasecmp(mdlist->devname, "<ignore>") == 0)
continue;
+ if (!is_mddev(mdlist->devname)) {
+ free_statelist(statelist);
+ return 1;
+ }
st = xcalloc(1, sizeof *st);
snprintf(st->devname, MD_NAME_MAX + sizeof("/dev/md/"),
"/dev/md/%s", basename(mdlist->devname));
- if (!is_mddev(mdlist->devname))
- return 1;
st->next = statelist;
st->devnm[0] = 0;
st->percent = RESYNC_UNKNOWN;
for (dv = devlist; dv; dv = dv->next) {
struct state *st;
- if (!is_mddev(dv->devname))
+ if (!is_mddev(dv->devname)) {
+ free_statelist(statelist);
return 1;
+ }
st = xcalloc(1, sizeof *st);
mdlist = conf_get_ident(dv->devname);
for (stp = &statelist; (st = *stp) != NULL; ) {
if (st->from_auto && st->err > 5) {
*stp = st->next;
- free(st->spare_group);
+ if (st->spare_group)
+ free(st->spare_group);
+
free(st);
} else
stp = &st->next;
}
}
- for (st2 = statelist; st2; st2 = statelist) {
- statelist = st2->next;
- free(st2);
- }
+
+ free_statelist(statelist);
if (pidfile)
unlink(pidfile);
}
}
+/**
+ * free_statelist() - Frees statelist.
+ * @statelist: statelist to free
+ */
+static void free_statelist(struct state *statelist)
+{
+ struct state *tmp = NULL;
+
+ while (statelist) {
+ if (statelist->spare_group)
+ free(statelist->spare_group);
+
+ tmp = statelist;
+ statelist = statelist->next;
+ free(tmp);
+ }
+}
+
#ifndef NO_LIBUDEV
/* function: check_udev_activity
* Description: Function waits for udev to finish