-/* $OpenBSD: disklabel.c,v 1.250 2023/06/19 13:45:19 krw Exp $ */
+/* $OpenBSD: disklabel.c,v 1.251 2023/06/21 12:50:09 krw Exp $ */
/*
* Copyright (c) 1987, 1993
if (errors > 0)
mpcopy(mountpoints, omountpoints);
- mpfree(omountpoints);
+ mpfree(omountpoints, DISCARD);
return (errors > 0);
}
-/* $OpenBSD: editor.c,v 1.410 2023/06/19 13:45:19 krw Exp $ */
+/* $OpenBSD: editor.c,v 1.411 2023/06/21 12:50:09 krw Exp $ */
/*
* Copyright (c) 1997-2000 Todd C. Miller <millert@openbsd.org>
}
}
done:
- mpfree(omountpoints);
- mpfree(origmountpoints);
- mpfree(tmpmountpoints);
+ mpfree(omountpoints, DISCARD);
+ mpfree(origmountpoints, DISCARD);
+ mpfree(tmpmountpoints, DISCARD);
return (error);
}
if (index >= alloc_table_nitems)
return 1;
lp = &label;
- for (i = 0; i < MAXPARTITIONS; i++) {
- free(mountpoints[i]);
- mountpoints[i] = NULL;
- }
+ mpfree(mountpoints, KEEP);
memcpy(lp, lp_org, sizeof(struct disklabel));
lp->d_npartitions = MAXPARTITIONS;
lastalloc = alloc_table[index].sz;
}
void
-mpfree(char **mp)
+mpfree(char **mp, int action)
{
int part;
if (mp == NULL)
return;
- for (part = 0; part < MAXPARTITIONS; part++)
+ for (part = 0; part < MAXPARTITIONS; part++) {
free(mp[part]);
+ mp[part] = NULL;
+ }
- free(mp);
+ if (action == DISCARD) {
+ free(mp);
+ mp = NULL;
+ }
}
int
{
int i;
- for (i = 0; i < MAXPARTITIONS; i++) {
- memset(&lp->d_partitions[i], 0, sizeof(struct partition));
- free(mountpoints[i]);
- mountpoints[i] = NULL;
- }
-
+ memset(lp->d_partitions, 0, sizeof(lp->d_partitions));
DL_SETPSIZE(&lp->d_partitions[RAW_PART], DL_GETDSIZE(lp));
+
+ mpfree(mountpoints, KEEP);
}
u_int64_t
-/* $OpenBSD: extern.h,v 1.35 2023/01/04 21:08:08 krw Exp $ */
+/* $OpenBSD: extern.h,v 1.36 2023/06/21 12:50:09 krw Exp $ */
/*
* Copyright (c) 2003 Theo de Raadt <deraadt@openbsd.org>
#define MEG(x) ((x) * 1024LL * (1024 / DEV_BSIZE))
#define GIG(x) (MEG(x) * 1024LL)
+/* 'actions' for mpfree(). */
+#define DISCARD 0
+#define KEEP 1
+
u_short dkcksum(const struct disklabel *);
char canonical_unit(const struct disklabel *, char);
double scale(u_int64_t, char, const struct disklabel *);
int editor_allocspace(struct disklabel *);
void mpsave(const struct disklabel *);
void mpcopy(char **, char **);
-void mpfree(char **);
+void mpfree(char **, int);
void parse_autotable(char *);
int writelabel(int, struct disklabel *);