diff --git a/include/trick/ExternalApplication.hh b/include/trick/ExternalApplication.hh index 3f133ea9..3e93930e 100644 --- a/include/trick/ExternalApplication.hh +++ b/include/trick/ExternalApplication.hh @@ -300,7 +300,7 @@ namespace Trick { /** alloc'd addresses to be deallocated during app destruction (currently only used by command_c_str) */ - std::vector allocations; + std::vector allocations; private: diff --git a/trick_source/sim_services/ExternalApplications/ExternalApplication.cpp b/trick_source/sim_services/ExternalApplications/ExternalApplication.cpp index 5b631fff..2ffcbd1c 100644 --- a/trick_source/sim_services/ExternalApplications/ExternalApplication.cpp +++ b/trick_source/sim_services/ExternalApplications/ExternalApplication.cpp @@ -15,6 +15,8 @@ #include "trick/variable_server_proto.h" #include "trick/env_proto.h" #include "trick/command_line_protos.h" +#include "trick/MemoryManager.hh" +extern Trick::MemoryManager* trick_MM; Trick::ExternalApplication::ExternalApplication() : command(std::string(env_get_var("TRICK_HOME") + std::string("/bin/"))) { @@ -23,21 +25,23 @@ Trick::ExternalApplication::ExternalApplication() : 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 = strdup(command.c_str()); - allocations.push_back((void*)command_c_str); + 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) { - free(*it); + for(std::vector::iterator it = allocations.begin(); it != allocations.end(); ++it) { + trick_MM->delete_var(*it); } allocations.clear(); } void Trick::ExternalApplication::set_startup_command(std::string in_command) { command = in_command; - command_c_str = strdup(in_command.c_str()); - allocations.push_back((void *) command_c_str); + 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() {