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.
ok?
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);