Reallocate a maxlen-long buffer only when the current maxlen is

shorter than the required length.  Note that it rarely happens
because maxlen is almost always 128 which covers struct sockaddr_storage.
This commit is contained in:
Hiroki Sato 2015-10-06 08:43:48 +00:00
parent 62d4443f00
commit c1d0909a53
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=288915

View File

@ -1051,17 +1051,19 @@ netbufcmp(struct netbuf *n1, struct netbuf *n2)
static bool_t
netbuf_copybuf(struct netbuf *dst, const struct netbuf *src)
{
assert(src->len <= src->maxlen);
if (dst->len != src->len || dst->buf == NULL) {
if (dst->maxlen < src->len || dst->buf == NULL) {
if (dst->buf != NULL)
free(dst->buf);
if ((dst->buf = malloc(src->len)) == NULL)
if ((dst->buf = calloc(1, src->maxlen)) == NULL)
return (FALSE);
dst->maxlen = dst->len = src->len;
dst->maxlen = src->maxlen;
}
dst->len = src->len;
memcpy(dst->buf, src->buf, src->len);
return (TRUE);
}