cpprestsdk icon indicating copy to clipboard operation
cpprestsdk copied to clipboard

Crash inside http_client constructor

Open derekao opened this issue 6 years ago • 4 comments

I've been following the microsoft tutorial, how ever i'm getting a crash and I cannot figure it out.

I'm using visual studio 2017 with C++11

I've codded a function GetRequest() that do work when used in a new empty project, but when I try to use it on my Project (Very big project with millions of code lines). I'm crashing in the constructor of http_client, in the file xmemory0 line 118.

const uintptr_t _Ptr_container = _Ptr_user[-1];

This is a link to the callstack : https://i.imgur.com/lBm0Hv7.png

void RestManager::GetRequest()
{
    auto fileStream = std::make_shared<ostream>();

    // Open stream to output file.
    pplx::task<void> requestTask = fstream::open_ostream(U("results.html")).then([=](ostream outFile)
    {
    	*fileStream = outFile;

	    // Create http_client to send the request.
	    http_client client(U("XXX/XXX.svc/"));

	    // Build request URI and start the request.
	    uri_builder builder(U("/IsLive"));
	    builder.append_query(U("q"), U("cpprestsdk github"));
	    return client.request(methods::GET, builder.to_string());
    })

	    // Handle response headers arriving.
	    .then([=](http_response response)
    {
	    printf("Received response status code:%u\n", response.status_code());

	    // Write response body into the file.
	return response.body().read_to_end(fileStream->streambuf());
    })    

	    // Close the file stream.
	    .then([=](size_t)
    {
	    return fileStream->close();
    });

    // Wait for all the outstanding I/O to complete and handle any exceptions
    try
    {
	    requestTask.wait();
    }
    catch (const std::exception &e)
    {
	    printf("Error exception:%s\n", e.what());
    }

}

The wierd thing is that it's not crashing when i just make a main() that call this function. I guess it must be due to some memory issues, however I have no idea how could I debug that. Does anyone would have an idea about it?

Thanks and have a great day!

derekao avatar May 13 '19 15:05 derekao

Did you find a solution? I am having the exact same problem, I'm just a newcomer to cpprestsdk and I'm trying to build the client sample exactly as it comes. http_client client(U("http://www.bing.com/")); crashes in the exact same line as yours. In the 64-bit version however, it crashes in _container_base12::Orphan_all() since _Myproxy value is 0xcccccccccccccccc.

malopezmx avatar May 11 '21 02:05 malopezmx

Has anyone been able to resolve this crash? Having the same issue.

sgravel129 avatar Apr 21 '23 13:04 sgravel129

I have the same issue. Does anyone would have an idea about it?

boplennon avatar Oct 25 '23 14:10 boplennon

Project Properties > Configuration > vcpkg > Vcpkg configuration > Debug solved problem for me

boplennon avatar Oct 25 '23 23:10 boplennon