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:
parent
62d4443f00
commit
c1d0909a53
Notes:
svn2git
2020-12-20 02:59:44 +00:00
svn path=/head/; revision=288915
@ -1051,17 +1051,19 @@ netbufcmp(struct netbuf *n1, struct netbuf *n2)
|
|||||||
static bool_t
|
static bool_t
|
||||||
netbuf_copybuf(struct netbuf *dst, const struct netbuf *src)
|
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)
|
if (dst->buf != NULL)
|
||||||
free(dst->buf);
|
free(dst->buf);
|
||||||
if ((dst->buf = malloc(src->len)) == NULL)
|
if ((dst->buf = calloc(1, src->maxlen)) == NULL)
|
||||||
return (FALSE);
|
return (FALSE);
|
||||||
|
dst->maxlen = src->maxlen;
|
||||||
dst->maxlen = dst->len = src->len;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
dst->len = src->len;
|
||||||
memcpy(dst->buf, src->buf, src->len);
|
memcpy(dst->buf, src->buf, src->len);
|
||||||
|
|
||||||
return (TRUE);
|
return (TRUE);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user