Skip to content

Conversation

aentinger
Copy link
Contributor

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
@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