diff --git a/src/file_storage.cpp b/src/file_storage.cpp index 99827b3ca..912bf1f49 100644 --- a/src/file_storage.cpp +++ b/src/file_storage.cpp @@ -216,7 +216,7 @@ namespace { internal_file_entry::~internal_file_entry() { - if (name_len == name_is_owned) ::free(const_cast(name)); + if (name_len == name_is_owned) delete[] name; } internal_file_entry::internal_file_entry(internal_file_entry const& fe) @@ -305,7 +305,7 @@ namespace { if (string_len >= name_is_owned) string_len = name_is_owned - 1; // free the current string, before assigning the new one - if (name_len == name_is_owned) ::free(const_cast(name)); + if (name_len == name_is_owned) delete[] name; if (n == nullptr) { TORRENT_ASSERT(borrow_string == false); diff --git a/src/http_parser.cpp b/src/http_parser.cpp index e5cb80bf6..f63a26d74 100644 --- a/src/http_parser.cpp +++ b/src/http_parser.cpp @@ -39,7 +39,7 @@ POSSIBILITY OF SUCH DAMAGE. #include "libtorrent/http_parser.hpp" #include "libtorrent/assert.hpp" #include "libtorrent/parse_url.hpp" // for parse_url_components -#include "libtorrent/string_util.hpp" // for allocate_string_copy +#include "libtorrent/string_util.hpp" // for ensure_trailing_slash, to_lower #include "libtorrent/aux_/escape_string.hpp" // for read_until namespace libtorrent { diff --git a/src/string_util.cpp b/src/string_util.cpp index 4a179acaf..30eeee320 100644 --- a/src/string_util.cpp +++ b/src/string_util.cpp @@ -168,9 +168,9 @@ namespace libtorrent { { if (str == nullptr) return nullptr; std::size_t const len = std::strlen(str); - char* tmp = static_cast(std::malloc(len + 1)); + char* tmp = new char[len + 1]; if (tmp == nullptr) return nullptr; - std::memcpy(tmp, str, len); + std::copy(str, str + len, tmp); tmp[len] = '\0'; return tmp; }