use new instead of malloc

This commit is contained in:
arvidn 2017-09-17 12:50:09 +02:00 committed by Arvid Norberg
parent 0232dc35cd
commit 646581f8a2
3 changed files with 5 additions and 5 deletions

View File

@ -216,7 +216,7 @@ namespace {
internal_file_entry::~internal_file_entry()
{
if (name_len == name_is_owned) ::free(const_cast<char*>(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<char*>(name));
if (name_len == name_is_owned) delete[] name;
if (n == nullptr)
{
TORRENT_ASSERT(borrow_string == false);

View File

@ -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 {

View File

@ -168,9 +168,9 @@ namespace libtorrent {
{
if (str == nullptr) return nullptr;
std::size_t const len = std::strlen(str);
char* tmp = static_cast<char*>(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;
}