Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: memory leak in tcp client writing holding register #302

Merged
merged 1 commit into from
Nov 29, 2024

Conversation

cdbennett
Copy link
Contributor

The call to BytesMut::reserve() was passing the total number of bytes we desired as the capacity, but reserve() takes only the additional number of bytes we expect to insert. This was resulting in an exponential explosion of the length and a crash after a couple dozen calls at most, with a message like

memory allocation of 34359738368 bytes failed

Fixes #301

The call to `BytesMut::reserve()` was passing the total number of bytes we
desired as the capacity, but `reserve()` takes only the additional number of
bytes we expect to insert. This was resulting in an exponential explosion of
the length and a crash after a couple dozen calls at most, with a message like

    memory allocation of 34359738368 bytes failed

Fixes slowtec#301
@cdbennett cdbennett force-pushed the fix-301-memory-leak-tcp-client branch from c1486d7 to e238ae1 Compare November 28, 2024 00:15
Copy link
Member

@uklotzde uklotzde left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for finding and fixing this serious bug!

@uklotzde uklotzde merged commit 8a886c8 into slowtec:main Nov 29, 2024
10 checks passed
@uklotzde
Copy link
Member

RTU was also affected: #304

@cdbennett cdbennett deleted the fix-301-memory-leak-tcp-client branch December 23, 2024 23:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

memory leak in tcp client when repeatedly writing holding register
2 participants