-
Notifications
You must be signed in to change notification settings - Fork 122
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
memory leak in tcp client when repeatedly writing holding register #301
Comments
Here an example on how to see the error: it is the tpc client example with a infinite loop, to make the 2 calls: on my pc crashes at iteration 21 saying:
|
cdbennett
added a commit
to cdbennett/tokio-modbus
that referenced
this issue
Nov 27, 2024
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
It appears this issue was introduced in main with #292, and it seems that it did not affect v0.15.0 or earlier. |
cdbennett
added a commit
to cdbennett/tokio-modbus
that referenced
this issue
Nov 28, 2024
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
# for free
to join this conversation on GitHub.
Already have an account?
# to comment
Hi, I think I found a memory leak bug:
I have a program that makes 2 holding register writes:
first call writes a value
second call writes 2 values (problem happens even with more number of values)
if you keep doing that, program will continue to double the ram needed because of this line in
src/coded/tcp.rs (line 136)
buf.reserve((buf.capacity() - buf_offset) + request_pdu_size + 7);
this happens on every iteration, you will see an initial 8KB usage than 16KB and so on till the program crashes
it does not matter that the server answers, problem will occur eventually
The text was updated successfully, but these errors were encountered: