diff --git a/include/exiv2/futils.hpp b/include/exiv2/futils.hpp index 5a322fc9..2bd71239 100644 --- a/include/exiv2/futils.hpp +++ b/include/exiv2/futils.hpp @@ -78,7 +78,7 @@ namespace Exiv2 { @note Be sure to free() the returned string after use Source: http://www.geekhideout.com/urlcode.shtml */ - EXIV2API std::string urlencode(char *str); + EXIV2API std::string urlencode(const char *str); /*! @brief Decode the input url. @param str The url needs decoding. diff --git a/src/futils.cpp b/src/futils.cpp index 88c5c1df..9b345fdf 100644 --- a/src/futils.cpp +++ b/src/futils.cpp @@ -71,9 +71,9 @@ namespace Exiv2 { return isdigit(ch) ? ch - '0' : tolower(ch) - 'a' + 10; } // from_hex - std::string urlencode(char* str) { - char* pstr = str; - char* buf = (char*)malloc(strlen(str) * 3 + 1); + std::string urlencode(const char* str) { + const char* pstr = str; + char* buf = new char[strlen(str) * 3 + 1]; char* pbuf = buf; while (*pstr) { if (isalnum(*pstr) || *pstr == '-' || *pstr == '_' || *pstr == '.' || *pstr == '~') @@ -86,7 +86,7 @@ namespace Exiv2 { } *pbuf = '\0'; std::string ret(buf); - free(buf); + delete [] buf; return ret; }