Michael McConville([email protected]) on 2015.10.28 12:05:24 -0400:
> Relayd, httpd, and ntpd define the functions get_data() and
> get_string(). Both call calloc and then immediately memcpy. Calloc's
> zeroing isn't optimized out. These functions are called in network data
> paths in at least a couple places, so all this extra writing could have
> a meaningful performance impact.

in relayd these functions are *not* called in the network path, they are used
when loading the (TLS) configuration data.

they dont have a performance impact.

> 
> 
> Index: relayd.c
> ===================================================================
> RCS file: /cvs/src/usr.sbin/relayd/relayd.c,v
> retrieving revision 1.144
> diff -u -p -r1.144 relayd.c
> --- relayd.c  14 Oct 2015 07:58:14 -0000      1.144
> +++ relayd.c  28 Oct 2015 15:57:16 -0000
> @@ -1501,9 +1501,10 @@ get_string(u_int8_t *ptr, size_t len)
>                   isspace((unsigned char)ptr[i])))
>                       break;
>  
> -     if ((str = calloc(1, i + 1)) == NULL)
> +     if ((str = malloc(i + 1)) == NULL)
>               return (NULL);
>       memcpy(str, ptr, i);
> +     str[i] = '\0';
>  
>       return (str);
>  }
> @@ -1513,7 +1514,7 @@ get_data(u_int8_t *ptr, size_t len)
>  {
>       u_int8_t        *data;
>  
> -     if ((data = calloc(1, len)) == NULL)
> +     if ((data = malloc(len)) == NULL)
>               return (NULL);
>       memcpy(data, ptr, len);
>  
> 

-- 

Reply via email to