Description
I built a simple example with sanitizer (added the parameter -fsanitizer = address, undefined in CXX_FLAGS). OS Debian 10.2 (gcc 8.3).
#include
#include <cpprest/http_client.h>
#include <cpprest/filestream.h>
#include <cpprest/uri.h>
#include <cpprest/json.h>
using namespace utility;
using namespace web;
using namespace web::http;
using namespace web::http::client;
using namespace concurrency::streams;
int main() {
// Create user data as JSON object and make POST request.
auto postJson = pplx::create_task( {
json::value jsonObject;
jsonObject[U("first_name")] = json::value::string(U("atakan"));
jsonObject[U("last_name")] = json::value::string(U("sarioglu"));
return http_client(U("https://reqres.in"))
.request(methods::POST,
uri_builder(U("api")).append_path(U("users")).to_string(),
jsonObject.serialize(), U("application/json"));
})
// Get the response.
.then([](http_response response) {
// Check the status code.
if (response.status_code() != 201) {
throw std::runtime_error("Returned " + std::to_string(response.status_code()));
}
// Convert the response body to JSON object.
return response.extract_json();
})
// Parse the user details.
.then([](json::value jsonObject) {
std::wcout << jsonObject[U("first_name")].as_string()
<< " " << jsonObject[U("last_name")].as_string()
<< " (" << jsonObject[U("id")].as_string() << ")"
<< std::endl;
});
try {
postJson.wait();
} catch (const std::exception &e) {
printf("Error exception:%s\n", e.what());
}
return 0;
}
Error:
/usr/local/include/cpprest/astreambuf.h:891:65: runtime error: member call on address 0x6070000039e0 which does not point to an object of type 'basic_streambuf'
0x6070000039e0: note: object is of type 'Concurrency::streams::details::basic_container_buffer<std::__cxx11::basic_string<char, std::char_traits, std::allocator > >'
01 00 80 2a 28 69 a5 90 e2 55 00 00 e0 39 00 00 70 60 00 00 70 1b 00 00 30 60 00 00 00 00 00 00
^~~~~~~~~~~~~~~~~~~~~~~
vptr for 'Concurrency::streams::details::basic_container_buffer<std::__cxx11::basic_string<char, std::char_traits, std::allocator > >'
string: {"id":1,"jsonrpc":"2.0","result":"4.4.4"}
=================================================================
==3619==ERROR: LeakSanitizer: detected memory leaks
Direct leak of 512 byte(s) in 2 object(s) allocated from:
#0 0x7f7bc2719720 in __interceptor_realloc (/lib/x86_64-linux-gnu/libasan.so.5+0xe9720)
#1 0x7f7bbb0bc292 (/lib/x86_64-linux-gnu/libstdc++.so.6+0x95292)
If without a sanitizer it is naturally not there.
More precisely, it is, just no one tells you about it (such as sanitizer).
Any thoughts on how to fix this?