diff --git a/include/exiv2/futils.hpp b/include/exiv2/futils.hpp index db674efe..4d7963ef 100644 --- a/include/exiv2/futils.hpp +++ b/include/exiv2/futils.hpp @@ -79,7 +79,7 @@ namespace Exiv2 @param str The url needs decoding. @return the url-decoded version of str. - @note Be sure to free() the returned string after use + @note Be sure to 'free' the returned string after use with 'delete []'. Source: http://www.geekhideout.com/urlcode.shtml @todo This function can probably be hidden into the implementation details */ diff --git a/src/futils.cpp b/src/futils.cpp index 5764357a..f2695132 100644 --- a/src/futils.cpp +++ b/src/futils.cpp @@ -102,7 +102,7 @@ namespace Exiv2 { char* urldecode(const char* str) { const char* pstr = str; - char* buf = (char*)malloc(strlen(str) + 1); + char* buf = new char [(strlen(str) + 1)]; char* pbuf = buf; while (*pstr) { if (*pstr == '%') { @@ -124,7 +124,7 @@ namespace Exiv2 { void urldecode(std::string& str) { char* decodeStr = Exiv2::urldecode(str.c_str()); str = std::string(decodeStr); - free(decodeStr); + delete [] decodeStr; } int base64encode(const void* data_buf, size_t dataLength, char* result, size_t resultSize) { diff --git a/unitTests/test_futils.cpp b/unitTests/test_futils.cpp index b9f50296..cba26946 100644 --- a/unitTests/test_futils.cpp +++ b/unitTests/test_futils.cpp @@ -96,7 +96,7 @@ TEST(urldecode, decodesGivenUrl) const std::string url ("http%3a%2f%2fwww.geekhideout.com%2furlcode.shtml"); char * url3 = urldecode(url.c_str()); ASSERT_STREQ(expectedDecodedUrl.c_str(), url3); - free(url3); + delete [] url3; } TEST(urldecode, decodesGivenUrlInPlace)