if_delgroup(): Add size to free(9) call

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

if_delgroup(): Add size to free(9) call

Klemens Nanni-2
Interface groups are allocated as follows:

        struct ifg_group *
        if_creategroup(const char *groupname)
        {
                struct ifg_group *ifg;

                if ((ifg = malloc(sizeof(*ifg), M_TEMP, M_NOWAIT)) == NULL)
                        return (NULL);

                ...
        }

Since this allocation per group does not change, we can use the same
size when freeing it in if_delgroup() accordingly.

Tested on sparc64.

Feedback? OK?


Index: sys/net/if.c
===================================================================
RCS file: /cvs/src/sys/net/if.c,v
retrieving revision 1.610
diff -u -p -r1.610 if.c
--- sys/net/if.c 22 Jun 2020 09:45:13 -0000 1.610
+++ sys/net/if.c 30 Jun 2020 02:00:31 -0000
@@ -2774,7 +2774,7 @@ if_delgroup(struct ifnet *ifp, const cha
 #if NPF > 0
  pfi_detach_ifgroup(ifgl->ifgl_group);
 #endif
- free(ifgl->ifgl_group, M_TEMP, 0);
+ free(ifgl->ifgl_group, M_TEMP, sizeof(*ifgl->ifgl_group));
  }
 
  free(ifgl, M_TEMP, sizeof(*ifgl));

Reply | Threaded
Open this post in threaded view
|

Re: if_delgroup(): Add size to free(9) call

Vitaliy Makkoveev
On Tue, Jun 30, 2020 at 04:11:59AM +0200, Klemens Nanni wrote:

> Interface groups are allocated as follows:
>
> struct ifg_group *
> if_creategroup(const char *groupname)
> {
> struct ifg_group *ifg;
>
> if ((ifg = malloc(sizeof(*ifg), M_TEMP, M_NOWAIT)) == NULL)
> return (NULL);
>
> ...
> }
>
> Since this allocation per group does not change, we can use the same
> size when freeing it in if_delgroup() accordingly.
>
> Tested on sparc64.
>
> Feedback? OK?
>

OK mvs