diff --git a/sources/client.cpp b/sources/client.cpp index 9f2e7b2..1ee1361 100644 --- a/sources/client.cpp +++ b/sources/client.cpp @@ -458,7 +458,9 @@ namespace WebDAV { pugi::xml_node href = response.node().select_node("*[local-name()='href']").node(); std::string encode_file_name = href.first_child().value(); - std::string resource_path = curl_unescape(encode_file_name.c_str(), static_cast(encode_file_name.length())); + char* unescaped = curl_unescape(encode_file_name.c_str(), static_cast(encode_file_name.length())); //this allocates new memory + std::string resource_path{unescaped}; // the data is copied + curl_free(unescaped); auto target_path = target_urn.path(); auto target_path_without_sep = target_urn.path(); if (!target_path_without_sep.empty() && target_path_without_sep.back() == '/') diff --git a/sources/urn.cpp b/sources/urn.cpp index 7ddbace..7448ed6 100644 --- a/sources/urn.cpp +++ b/sources/urn.cpp @@ -81,7 +81,9 @@ namespace WebDAV auto escape(void* request, const string& name) -> string { - string path = curl_easy_escape(request, name.c_str(), static_cast(name.length())); + char * escaped = curl_easy_escape(request, name.c_str(), static_cast(name.length())); // allocates new memory + string path{escaped}; // this copies the data + curl_free(escaped); // must free the memory return path; }