}
static void
-discard_mntentchn(struct mntentchn *mc0) {
- struct mntentchn *mc, *mc1;
-
- for (mc = mc0->nxt; mc && mc != mc0; mc = mc1) {
- mc1 = mc->nxt;
+my_free_mc(struct mntentchn *mc) {
+ if (mc) {
my_free(mc->m.mnt_fsname);
my_free(mc->m.mnt_dir);
my_free(mc->m.mnt_type);
}
}
+
+static void
+discard_mntentchn(struct mntentchn *mc0) {
+ struct mntentchn *mc, *mc1;
+
+ for (mc = mc0->nxt; mc && mc != mc0; mc = mc1) {
+ mc1 = mc->nxt;
+ my_free_mc(mc);
+ }
+}
+
static void
read_mntentchn(mntFILE *mfp, const char *fnam, struct mntentchn *mc0) {
struct mntentchn *mc = mc0;
if (mc && mc != mc0) {
mc->prev->nxt = mc->nxt;
mc->nxt->prev = mc->prev;
- free(mc);
+ my_free_mc(mc);
}
} else if (!strcmp(mc->m.mnt_dir, instead->mnt_dir)) {
/* A remount */
- mc->m.mnt_opts = instead->mnt_opts;
+ my_free(mc->m.mnt_opts);
+ mc->m.mnt_opts = xstrdup(instead->mnt_opts);
} else {
/* A move */
my_free(mc->m.mnt_dir);
} else if (instead) {
/* not found, add a new entry */
absent = xmalloc(sizeof(*absent));
- absent->m = *instead;
+ absent->m.mnt_fsname = xstrdup(instead->mnt_fsname);
+ absent->m.mnt_dir = xstrdup(instead->mnt_dir);
+ absent->m.mnt_type = xstrdup(instead->mnt_type);
+ absent->m.mnt_opts = xstrdup(instead->mnt_opts);
+ absent->m.mnt_freq = instead->mnt_freq;
+ absent->m.mnt_passno = instead->mnt_passno;
absent->nxt = mc0;
absent->prev = mc0->prev;
mc0->prev = absent;
int errsv = errno;
error (_("cannot open %s (%s) - mtab not updated"),
MOUNTED_TEMP, strerror (errsv));
+ discard_mntentchn(mc0);
goto leave;
}