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

Bugfix: premature deletion of socket causes hard-fault when opcua-client disconnects. #5

Merged
merged 1 commit into from
Jun 19, 2024

Conversation

aentinger
Copy link
Collaborator

When an incoming connection is accepted by TCPSocket::accept() a new TCPSocket is generated and allocated on the heap. At the same time a TCPSocket internal flag called "_factory_allocated" is set which causes the dynamically allocated memory to be deallocated when calling TCPSocket::close().

As a consequence there is no need to deallocate or close any TCPSocket object in "shutdown", as this is done when calling UA_close (= mbed_close). Calling TCPSocket::close already here would also cause a crash as the object would have been deallocated by the time the OPCUA stack would invoke UA_close.

@aentinger aentinger added type: imperfection Perceived defect in any part of project topic: code Related to content of the project itself labels Jun 19, 2024
@aentinger aentinger self-assigned this Jun 19, 2024
…ent disconnects.

When an incoming connection is accepted by TCPSocket::accept()
a new TCPSocket is generated and allocated on the heap. At the
same time a TCPSocket internal flag called "_factory_allocated"
is set which causes the dynamically allocated memory to be
deallocated when calling TCPSocket::close().

As a consequence there is no need to deallocate or close any
TCPSocket object in "shutdown", as this is done when calling
UA_close (= mbed_close). Calling TCPSocket::close already here
would also cause a crash as the object would have been deallocated
by the time the OPCUA stack would invoke UA_close.
@aentinger aentinger force-pushed the fix-firmware-stack-crash-on-close branch from 72ca5d3 to 905b63a Compare June 19, 2024 11:20
Copy link

Memory usage change @ 905b63a

Board flash % RAM for global variables %
arduino:mbed_opta:opta 0 - 0 0.0 - 0.0 0 - 0 0.0 - 0.0
Click for full report table
Board examples/opcua_server
flash
% examples/opcua_server
RAM for global variables
%
arduino:mbed_opta:opta 0 0.0 0 0.0
Click for full report CSV
Board,examples/opcua_server<br>flash,%,examples/opcua_server<br>RAM for global variables,%
arduino:mbed_opta:opta,0,0.0,0,0.0

@aentinger aentinger merged commit 96f79b9 into main Jun 19, 2024
6 checks passed
@aentinger aentinger deleted the fix-firmware-stack-crash-on-close branch June 19, 2024 11:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
topic: code Related to content of the project itself type: imperfection Perceived defect in any part of project
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant