diff --git a/src/ConfigurationHelper.cpp b/src/ConfigurationHelper.cpp index 8cccec1..bd475ba 100644 --- a/src/ConfigurationHelper.cpp +++ b/src/ConfigurationHelper.cpp @@ -318,9 +318,9 @@ bool ConfigurationHelper::applyConfOnTyplibValue(Typelib::Value &value, const Co for(const std::shared_ptr val: array->getValues()) { - - //TODO check, this may be a memory leak - Typelib::Value v(new uint8_t[indirect.getSize()], indirect); + std::vector storage; + storage.resize(indirect.getSize()); + Typelib::Value v(storage.data(), indirect); Typelib::init(v); Typelib::zero(v); @@ -416,7 +416,10 @@ bool ConfigurationHelper::applyConfigValueOnDSB(RTT::base::DataSourceBase::share //write value back typelibTransport->writeDataSource(*dsb, handle); - + + //delete all referenced memory to avoid memory leak + Typelib::destroy(dest); + //destroy handle to avoid memory leak typelibTransport->deleteHandle(handle); @@ -554,7 +557,12 @@ bool ConfigurationHelper::registerOverride(const std::string& taskName, Configur } YAML::Emitter &toYAML(YAML::Emitter &out, const Typelib::Numeric &type, const Typelib::Value &value){ - + if (type.getName() == "/bool") + { + //the /bool type must be output as "true" or "false" + out << (*static_cast(value.getData())?"true":"false"); + return out; + } switch(type.getNumericCategory()) { case Typelib::Numeric::Float: @@ -571,7 +579,8 @@ YAML::Emitter &toYAML(YAML::Emitter &out, const Typelib::Numeric &type, const Ty switch(type.getSize()) { case sizeof(int8_t): - out << *(static_cast(value.getData())); + //need to cast uint8_t to int so it is not interpreted as character but as number + out << static_cast(*(static_cast(value.getData()))); break; case sizeof(int16_t): out << *(static_cast(value.getData())); @@ -593,7 +602,8 @@ YAML::Emitter &toYAML(YAML::Emitter &out, const Typelib::Numeric &type, const Ty switch(type.getSize()) { case sizeof(uint8_t): - out << *(static_cast(value.getData())); + //need to cast uint8_t to unsigned int so it is not interpreted as character but as number + out << static_cast(*(static_cast(value.getData()))); break; case sizeof(uint16_t): out << *(static_cast(value.getData())); diff --git a/src/TypeWrapper.cpp b/src/TypeWrapper.cpp index ed89242..a57c0af 100644 --- a/src/TypeWrapper.cpp +++ b/src/TypeWrapper.cpp @@ -93,7 +93,7 @@ double TypeWrapper::toDouble() { } case Typelib::Numeric::SInt: switch (numeric.getSize()) { - case sizeof(int8_t): return static_cast(*static_cast(value.getData())); + case sizeof(int8_t): return *static_cast(value.getData()); case sizeof(int16_t): return *static_cast(value.getData()); case sizeof(int32_t): return *static_cast(value.getData()); case sizeof(int64_t): return *static_cast(value.getData()); @@ -103,7 +103,7 @@ double TypeWrapper::toDouble() { } case Typelib::Numeric::UInt: { switch (numeric.getSize()) { - case sizeof(uint8_t): return static_cast(*static_cast(value.getData())); + case sizeof(uint8_t): return *static_cast(value.getData()); case sizeof(uint16_t): return *static_cast(value.getData()); case sizeof(uint32_t): return *static_cast(value.getData()); case sizeof(uint64_t): return *static_cast(value.getData());