Size for free(9).
authormpi <mpi@openbsd.org>
Mon, 18 Dec 2017 09:40:17 +0000 (09:40 +0000)
committermpi <mpi@openbsd.org>
Mon, 18 Dec 2017 09:40:17 +0000 (09:40 +0000)
From <kshe59 at zoho.eu>

sys/net/rtsock.c

index c3d1f6d..6a516bf 100644 (file)
@@ -1,4 +1,4 @@
-/*     $OpenBSD: rtsock.c,v 1.258 2017/12/13 08:59:02 mpi Exp $        */
+/*     $OpenBSD: rtsock.c,v 1.259 2017/12/18 09:40:17 mpi Exp $        */
 /*     $NetBSD: rtsock.c,v 1.18 1996/03/29 00:32:10 cgd Exp $  */
 
 /*
@@ -980,7 +980,8 @@ change:
                                /* if gateway changed remove MPLS information */
                                if (rt->rt_llinfo != NULL &&
                                    rt->rt_flags & RTF_MPLS) {
-                                       free(rt->rt_llinfo, M_TEMP, 0);
+                                       free(rt->rt_llinfo, M_TEMP,
+                                           sizeof(struct rt_mpls));
                                        rt->rt_llinfo = NULL;
                                        rt->rt_flags &= ~RTF_MPLS;
                                }
@@ -1363,22 +1364,20 @@ again:
        /* align message length to the next natural boundary */
        len = ALIGN(len);
        if (cp == 0 && w != NULL && !second_time) {
-               struct walkarg *rw = w;
-
-               rw->w_needed += len;
-               if (rw->w_needed <= 0 && rw->w_where) {
-                       if (rw->w_tmemsize < len) {
-                               free(rw->w_tmem, M_RTABLE, 0);
-                               rw->w_tmem = malloc(len, M_RTABLE, M_NOWAIT);
-                               if (rw->w_tmem)
-                                       rw->w_tmemsize = len;
+               w->w_needed += len;
+               if (w->w_needed <= 0 && w->w_where) {
+                       if (w->w_tmemsize < len) {
+                               free(w->w_tmem, M_RTABLE, w->w_tmemsize);
+                               w->w_tmem = malloc(len, M_RTABLE, M_NOWAIT);
+                               if (w->w_tmem)
+                                       w->w_tmemsize = len;
                        }
-                       if (rw->w_tmem) {
-                               cp = rw->w_tmem;
+                       if (w->w_tmem) {
+                               cp = w->w_tmem;
                                second_time = 1;
                                goto again;
                        } else
-                               rw->w_where = 0;
+                               w->w_where = 0;
                }
        }
        if (cp && w)            /* clear the message header */
@@ -1809,7 +1808,7 @@ sysctl_rtable(int *name, u_int namelen, void *where, size_t *given, void *new,
                NET_UNLOCK();
                break;
        }
-       free(w.w_tmem, M_RTABLE, 0);
+       free(w.w_tmem, M_RTABLE, w.w_tmemsize);
        w.w_needed += w.w_given;
        if (where) {
                *given = w.w_where - (caddr_t)where;