From c8eb44e1fc99c9f978b473d6f5240fc2de3da12a Mon Sep 17 00:00:00 2001 From: Scott Fennell Date: Thu, 3 Oct 2019 16:19:36 -0500 Subject: [PATCH] get rid of dangling pointer use closes #878 --- .../sim_services/VariableServer/var_server_ext.cpp | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/trick_source/sim_services/VariableServer/var_server_ext.cpp b/trick_source/sim_services/VariableServer/var_server_ext.cpp index 4cb9610d..a92c63a7 100644 --- a/trick_source/sim_services/VariableServer/var_server_ext.cpp +++ b/trick_source/sim_services/VariableServer/var_server_ext.cpp @@ -1,5 +1,6 @@ #include +#include #include "trick/VariableServer.hh" #include "trick/exec_proto.h" @@ -530,11 +531,14 @@ int var_set_base( const char * var , T value , const char * units ) { v_tree.v_data = &v_data ; var_set_value( v_data , value) ; if ( units != NULL ) { - ref->units = (char *)(map_trick_units_to_udunits(units).c_str()) ; + ref->units = strdup(map_trick_units_to_udunits(units).c_str()) ; } else { - ref->units = (char *)units ; + ref->units = NULL ; } ref_assignment(ref , &v_tree) ; + if(ref->units != NULL) { + free(ref->units) ; + } free(ref) ; } else { message_publish(MSG_WARNING,"Cannot assign to %s because io_spec does not allow input\n", var) ;