diff --git a/test/test_nr1.cc b/test/test_nr1.cc index 21514fa..2972e29 100644 --- a/test/test_nr1.cc +++ b/test/test_nr1.cc @@ -213,7 +213,7 @@ namespace pEp { ~String() { if (_is_owner) { - _free(); + _free(*_c_str_pp); } } @@ -226,7 +226,7 @@ namespace pEp { } // DEALLOCATION - _free(); + _free(*_c_str_pp); // ALLOCATION *_c_str_pp = _copy(str); @@ -296,22 +296,17 @@ namespace pEp { static bool log_enabled; private: - // TODO: this is dodgy, do we really need _c_str_pp AND _c_str_p??? - void _free() + static char* _copy(const std::string& str) { - pEpLogClass("called"); - // if the c_str points to a different address now, than the one we created - if (*_c_str_pp != _c_str_p) { - // a new string has been created, and we need to free it as well - pEpLogClass("raw access string change detected"); - pEp::free(*_c_str_pp); - } else { - // WE ASSUME THAT: - // if the char* has been replaced, it has been freed, as well - if (_c_str_p != nullptr) { - pEp::free(_c_str_p); - } - } + char* ret = strdup(str.c_str()); + pEpLog(CXX::Inspect::all(ret)); + return ret; + } + + static void _free(char* ptr_type) + { + pEpLog(CXX::Inspect::all(ptr_type)); + ::pEp_free(ptr_type); } bool _is_bound{ false };