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

2020-06-30 Thread 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



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

2020-06-29 Thread Klemens Nanni
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.c22 Jun 2020 09:45:13 -  1.610
+++ sys/net/if.c30 Jun 2020 02:00:31 -
@@ -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));