szaszm commented on a change in pull request #1219:
URL: https://github.com/apache/nifi-minifi-cpp/pull/1219#discussion_r782082669



##########
File path: extensions/http-curl/client/HTTPClient.cpp
##########
@@ -212,7 +212,10 @@ void HTTPClient::setContentType(std::string content_type) {
 }
 
 std::string HTTPClient::escape(std::string string_to_escape) {
-  return curl_easy_escape(http_session_, string_to_escape.c_str(), 
gsl::narrow<int>(string_to_escape.length()));
+  char* escaped_chars = curl_easy_escape(http_session_, 
string_to_escape.c_str(), gsl::narrow<int>(string_to_escape.length()));
+  std::string escaped_string(escaped_chars);
+  curl_free(escaped_chars);
+  return escaped_string;

Review comment:
       In theory string's constructor can throw which would result in leaking 
`escaped_chars`. Consider using `unique_ptr` with a custom curl deleter.
   In practice it will never fail to allocate on linux, but will rather block 
indefinitely until there is an available page. On Windows, bad_alloc is 
possible.
   ```suggestion
     struct curl_deleter { void operator()(void* p) noexcept { curl_free(p); } 
};
     std::unique_ptr<char, curl_deleter> 
escaped_chars{curl_easy_escape(http_session_, string_to_escape.c_str(), 
gsl::narrow<int>(string_to_escape.length()))};
     std::string escaped_string(escaped_chars.get());
     return escaped_string;
   ```




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


Reply via email to