Skip to content

Commit

Permalink
Fix SCTP buffer reallocation for fewer reallocations with small fragm…
Browse files Browse the repository at this point in the history
…ent size
  • Loading branch information
RaimoNiskanen committed Sep 19, 2024
1 parent d3cb78e commit 73e1aa1
Showing 1 changed file with 14 additions and 10 deletions.
24 changes: 14 additions & 10 deletions erts/emulator/drivers/common/inet_drv.c
Original file line number Diff line number Diff line change
Expand Up @@ -14646,16 +14646,20 @@ static int packet_inet_input(udp_descriptor* udesc, HANDLE event)
ErlDrvBinary* tmp;
int bufsz;
ASSERT(IS_SCTP(desc));
bufsz = desc->bufsz + (udesc->i_ptr - udesc->i_buf->orig_bytes);
if ((tmp = realloc_buffer(udesc->i_buf, bufsz)) == NULL) {
release_buffer(udesc->i_buf);
udesc->i_buf = NULL;
return packet_error(udesc, ENOMEM);
}
udesc->i_ptr =
tmp->orig_bytes + (udesc->i_ptr - udesc->i_buf->orig_bytes);
udesc->i_buf = tmp;
udesc->i_bufsz = bufsz;
bufsz = udesc->i_ptr - udesc->i_buf->orig_bytes;
if (udesc->i_bufsz - bufsz < desc->bufsz) { /* Headroom */
bufsz = udesc->i_bufsz + desc->bufsz;
if ((tmp = realloc_buffer(udesc->i_buf, bufsz)) == NULL) {
release_buffer(udesc->i_buf);
udesc->i_buf = NULL;
return packet_error(udesc, ENOMEM);
}
udesc->i_ptr =
tmp->orig_bytes +
(udesc->i_ptr - udesc->i_buf->orig_bytes);
udesc->i_buf = tmp;
udesc->i_bufsz = bufsz;
}
have_fragment = TRUE;
} else
#endif
Expand Down

0 comments on commit 73e1aa1

Please sign in to comment.