mrtazz / restclient-cpp

C++ client for making HTTP/REST requests
http://code.mrtazz.com/restclient-cpp/
MIT License
1.57k stars 377 forks source link

valgrind #173

Open shi-bmz opened 3 years ago

shi-bmz commented 3 years ago

Hi,

Thanks for this handy library! I've already found a fix for this issue, but would prefer not to have to fork the project. If I can be allowed to push a feature branch to this repo, I'd be happy to share my fix. I don't know what kind of changes (if any) would be needed to the test suite, and unfortunately I don't have the time to figure that out. The fix is simply as follows, in include/restclient-cpp/connection.h:267:

    char curlErrorBuf[CURL_ERROR_SIZE] = {0};  // initialize array to prevent valgrind errors

Expected behaviour

no memory leaks in valgrind

Actual behaviour

Relevant part of valgrind output:

...
==32204== Conditional jump or move depends on uninitialised value(s)
==32204==    at 0x405DFB: std::char_traits<char>::length(char const*) (char_traits.h:320)
==32204==    by 0x406099: std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::basic_string(char const*, std::allocator<char> const&) (basic_string.h:511)
==32204==    by 0x7D6E036: RestClient::Connection::performCurlRequest(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, RestClient::Response*) (connection.cc:533)
==32204==    by 0x7D6D636: RestClient::Connection::performCurlRequest(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&) (connection.cc:367)
==32204==    by 0x7D6E2F4: RestClient::Connection::get(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&) (connection.cc:567)
==32204==    by 0x7D6BB44: RestClient::get(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&) (restclient.cc:58)
...

Environment and debugging details

montdidier commented 8 months ago

Noting this should be fixed - in the next release. 0.5.3