Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/usr.sbin/sysinst Do not free() an array embedded in another ...



details:   https://anonhg.NetBSD.org/src/rev/0442c9f771c7
branches:  trunk
changeset: 1000469:0442c9f771c7
user:      martin <martin%NetBSD.org@localhost>
date:      Thu Jul 25 18:55:40 2019 +0000

description:
Do not free() an array embedded in another structure

diffstat:

 usr.sbin/sysinst/mbr.c |  31 +++++++++++++------------------
 1 files changed, 13 insertions(+), 18 deletions(-)

diffs (63 lines):

diff -r 3c78e28607b8 -r 0442c9f771c7 usr.sbin/sysinst/mbr.c
--- a/usr.sbin/sysinst/mbr.c    Thu Jul 25 16:28:10 2019 +0000
+++ b/usr.sbin/sysinst/mbr.c    Thu Jul 25 18:55:40 2019 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: mbr.c,v 1.17 2019/07/25 13:16:35 martin Exp $ */
+/*     $NetBSD: mbr.c,v 1.18 2019/07/25 18:55:40 martin Exp $ */
 
 /*
  * Copyright 1997 Piermont Information Systems Inc.
@@ -223,13 +223,20 @@
 #endif
 
 static void
+free_last_mounted(mbr_info_t *m)
+{
+       size_t i;
+
+       for (i = 0; i < MBR_PART_COUNT; i++)
+               free(__UNCONST(m->last_mounted[i]));
+}
+
+static void
 free_mbr_info(mbr_info_t *m)
 {
        if (m == NULL)
                return;
-
-       for (int i = 0; i < MBR_PART_COUNT; i++)
-               free(__UNCONST(m->last_mounted[i]));
+       free_last_mounted(m);
        free(m);
 }
 
@@ -439,19 +446,6 @@
 }
 #endif
 
-static void
-free_mbr(mbr_info_t *mbri)
-{
-       mbr_info_t *m = mbri->extended, *next;
-
-       while (m != NULL) {
-               next = m->extended;
-               free_mbr_info(m);
-               m = next;
-       }
-       free_mbr_info(mbri);
-}
-
 static int
 valid_mbr(struct mbr_sector *mbrs)
 {
@@ -2390,7 +2384,8 @@
        if (parts->dlabel)
                parts->dlabel->pscheme->free(parts->dlabel);
 
-       free_mbr(&parts->mbr);
+       free_mbr_info(parts->mbr.extended);
+       free_last_mounted(&parts->mbr);
        free(parts);
 }
 



Home | Main Index | Thread Index | Old Index