Skip to content

Commit

Permalink
Merge pull request #518 from lf-lang/port-number-mem-bug
Browse files Browse the repository at this point in the history
Fix memory bug when obtaining a port number
  • Loading branch information
erlingrj authored Feb 11, 2025
2 parents 1e0267b + ced9486 commit 141dee7
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions core/federated/federate.c
Original file line number Diff line number Diff line change
Expand Up @@ -1978,10 +1978,13 @@ void lf_connect_to_rti(const char* hostname, int port) {

void lf_create_server(int specified_port) {
assert(specified_port <= UINT16_MAX && specified_port >= 0);
if (create_server(specified_port, &_fed.server_socket, (uint16_t*)&_fed.server_port, TCP, false)) {
uint16_t final_port;
if (create_server(specified_port, &_fed.server_socket, &final_port, TCP, false)) {
lf_print_error_system_failure("RTI failed to create TCP server: %s.", strerror(errno));
};
LF_PRINT_LOG("Server for communicating with other federates started using port %d.", _fed.server_port);

LF_PRINT_LOG("Server for communicating with other federates started using port %u.", final_port);
_fed.server_port = final_port;

// Send the server port number to the RTI
// on an MSG_TYPE_ADDRESS_ADVERTISEMENT message (@see net_common.h).
Expand Down

0 comments on commit 141dee7

Please sign in to comment.