Substitute malloc/free with new/delete
This commit is contained in:
parent
08cbb0c206
commit
eb306fdbae
@ -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
|
||||
*/
|
||||
|
||||
@ -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) {
|
||||
|
||||
@ -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)
|
||||
|
||||
Loading…
Reference in New Issue
Block a user