@@ -82,22 +82,20 @@ void curl_easy::perform() {
82
82
83
83
// Implementation of escape method.
84
84
void curl_easy::escape (string &url) {
85
- char *url_encoded = curl_easy_escape (this ->curl ,url.c_str (),(int )url.length ());
86
- if (url_encoded == nullptr ) {
87
- throw curl_easy_exception (" Null pointer intercepted" ,__FUNCTION__);
85
+ std::unique_ptr< char , void (*)( char *)> url_encoded ( curl_easy_escape (this ->curl , url.c_str (), (int )url.length ()), []( char *ptr) { curl_free (ptr); } );
86
+ if (! url_encoded) {
87
+ throw curl_easy_exception (" Null pointer intercepted" , __FUNCTION__);
88
88
}
89
- url = string (url_encoded);
90
- curl_free (url_encoded);
89
+ url = string (url_encoded.get ());
91
90
}
92
91
93
92
// Implementation of unescape method.
94
93
void curl_easy::unescape (string &url) {
95
- char *url_decoded = curl_easy_unescape (this ->curl ,url.c_str (),(int )url.length (),nullptr );
94
+ std::unique_ptr< char , void (*)( char *)> url_decoded ( curl_easy_unescape (this ->curl ,url.c_str (),(int )url.length (),nullptr ),[]( char *ptr) { curl_free (ptr); } );
96
95
if (url_decoded == nullptr ) {
97
96
throw curl_easy_exception (" Null pointer intercepted" ,__FUNCTION__);
98
97
}
99
- url = string (url_decoded);
100
- curl_free (url_decoded);
98
+ url = string (url_decoded.get ());
101
99
}
102
100
103
101
// Implementation of reset method.
0 commit comments