Azure / azure-storage-cpplite

Lite version of C++ Client Library for Microsoft Azure Storage
MIT License
25 stars 43 forks source link

Heap Corruption when using build_request #49

Closed raghujayan closed 4 years ago

raghujayan commented 4 years ago

The following snippet of code causes a heap corruption when calling the destructor:

 CurlEasyRequest::~CurlEasyRequest()
    {
        curl_easy_reset(m_curl);
        m_client->release_handle(m_curl);
        if (m_slist) {
            curl_slist_free_all(m_slist);
        }
    }

at the curl_easy_reset method call. It seems like m_curl gets freed before it gets here.

The code snippet that causes the issue:

std::shared_ptr<storage_account> account = std::make_shared<storage_account>(_accountName, _pcCredentials, /* use_https */ true);
  std::shared_ptr<blob_client > blobClient = std::make_shared<blob_client>(account, 1);  

  auto http_request = blobClient->client()->get_handle();

   return 0; /// The heap corruption happens after exiting from the method 

The vdsremote_blob_request at this point simply is a child class of get_blob_request_base.

My idea to use build_request is to get to the signed headers which (headers) we will be using internally in our curl requests. Let me know if there is another way to approach this problem and this is not the intended way.

While I understand the reason for curl handle being a raw pointer, I am wondering if it gets freed before all the "references" to it.

Appreciate any inputs.

Jinming-Hu commented 4 years ago

Hi @raghujayan, I'm sorry but I didn't get your point. m_curl will only be destructed in destructor of CurlEasyClient, and CurlEasyRequest holds a shared pointer of CurlEasyClient, which means m_curl should always be valid before the end of CurlEasyRequest's destructor.

I didn't mean this curl wrapper code is bug-free, actually on the contrary, I did observe some crash/heap corruption issues when firing thousands of requests in a few seconds. Did you come across any this kind of issues? If so, it'll be a great help to us if you can stably reproduce it. Thanks.

raghujayan commented 4 years ago

@JinmingHu-MSFT, thank you for taking a look at this issue. Our use case is to use the sdk to get the headers for GET requests. We are using our own curl based blob access which needs various forms of signing and we use the azure-storage-cpplite sdk for it. Currently this issue unfortunately is blocking us.

The code snippet I pasted above by itself causes a heap corruption issue. If you could try running the snippet above on windows and linking the code to dynamic libs for azure-cpp-lite and curl, you might potentially see the issue I am referring to,

If that does not help you to reproduce the issue. I will look at it some more.

Appreciate you help. Thank you

Jinming-Hu commented 4 years ago

Hi @raghujayan, I noticed you've closed this issue. Did you figure it out by yourself? If so, can you share what the real problem is and your solution? It'll be very helpful in improving our sdk, thanks.

raghujayan commented 4 years ago

User error. There was nothing wrong with the sdk. I accidentally mixed up the release lib with the debug build when linking curl