From 077064f225c75ed5c2a8126961cdaec192a69573 Mon Sep 17 00:00:00 2001 From: Hong Chen Date: Thu, 26 Sep 2024 11:17:57 -0500 Subject: [PATCH] Fixed one warning message at shutdown after checkpoint load and kept the current multicast group after checkpoint load. (#1784) * Added a check before calling MM delete_var in ExternalApplication destructor; Made sure that the MulticastGroup is not initialized before initializing it in VariableServerListenThread.cpp; * Updated to call multicast group initialization to be consistent for the unit test. * Removed unnecessary command c str pointer. * Removed unnecessary command c str pointer. --- include/trick/ExternalApplication.hh | 7 ------- .../ExternalApplications/ExternalApplication.cpp | 14 +------------- .../VariableServer/VariableServerListenThread.cpp | 5 ++++- 3 files changed, 5 insertions(+), 21 deletions(-) diff --git a/include/trick/ExternalApplication.hh b/include/trick/ExternalApplication.hh index 3e93930e..3b87d925 100644 --- a/include/trick/ExternalApplication.hh +++ b/include/trick/ExternalApplication.hh @@ -295,13 +295,6 @@ namespace Trick { /** Command to execute when starting this application. */ std::string command; - /** Pointer to alloc'd command c str for use with external application c_intf */ - char * command_c_str; - - /** alloc'd addresses to be deallocated during app destruction (currently only - used by command_c_str) */ - std::vector allocations; - private: /** Prevent SWIG from trying to invoke operator= on ostringstream. */ diff --git a/trick_source/sim_services/ExternalApplications/ExternalApplication.cpp b/trick_source/sim_services/ExternalApplications/ExternalApplication.cpp index ac377799..1e540e92 100644 --- a/trick_source/sim_services/ExternalApplications/ExternalApplication.cpp +++ b/trick_source/sim_services/ExternalApplications/ExternalApplication.cpp @@ -19,25 +19,13 @@ Trick::ExternalApplication::ExternalApplication() : host_source = port_source = AUTO; cycle_period_set = minimum_cycle_period_set = disconnect_behavior_set = height_set = width_set = x_set = y_set = auto_reconnect_set = false; - - // c_intf uses char *, we manage the memory here in external application - command_c_str = (char*)trick_MM->declare_var("char", (command.size() + 1) ); - strcpy(command_c_str, command.c_str()); - allocations.push_back(command_c_str); } Trick::ExternalApplication::~ExternalApplication() { - for(std::vector::iterator it = allocations.begin(); it != allocations.end(); ++it) { - trick_MM->delete_var( (void*)*it ); - } - allocations.clear(); } void Trick::ExternalApplication::set_startup_command(std::string in_command) { command = in_command; - command_c_str = (char*)trick_MM->declare_var("char", (command.size() + 1) ); - strcpy(command_c_str, command.c_str()); - allocations.push_back((command_c_str)); } std::string Trick::ExternalApplication::get_startup_command() { @@ -45,7 +33,7 @@ std::string Trick::ExternalApplication::get_startup_command() { } const char * Trick::ExternalApplication::get_startup_command_c_str() { - return command_c_str; + return command.c_str(); } void Trick::ExternalApplication::add_arguments(std::string args) { diff --git a/trick_source/sim_services/VariableServer/VariableServerListenThread.cpp b/trick_source/sim_services/VariableServer/VariableServerListenThread.cpp index 643df11a..4c43bfd6 100644 --- a/trick_source/sim_services/VariableServer/VariableServerListenThread.cpp +++ b/trick_source/sim_services/VariableServer/VariableServerListenThread.cpp @@ -248,7 +248,10 @@ int Trick::VariableServerListenThread::restart() { message_publish(MSG_INFO, "restart variable server message port = %d\n", _listener->getPort()); } - initializeMulticast(); + // Don't initialize the multicast group if it's already initialized + if (!_multicast->isInitialized()) { + initializeMulticast(); + } return 0 ; }