簡體   English   中英

使用curl_easy_cleanup(curl)時接收未處理的NULL異常

[英]Receiving unhandled NULL exception when using curl_easy_cleanup(curl)

我有一個Unity應用程序,它使用我編寫的用於發出http請求的c ++插件。 該插件使用curl庫。

根據curl文檔,他們建議使用curl_easy_cleanup(curl)作為最后一個命令,以釋放句柄並清理所有資源。

這是我的代碼,它發出了一個簡單的http POST請求:

struct curl_slist *headers = NULL;
CURL *curl = NULL;
curl  = curl_easy_init();
int httpCode(0);

if(curl)
{
    headers = curl_slist_append(headers, "Accept: application/json");
    headers = curl_slist_append(headers, "Content-Type: application/json");
    headers = curl_slist_append(headers, "charsets: utf-8");

    curl_easy_setopt(curl, CURLOPT_VERBOSE, 1L);
    curl_easy_setopt(curl, CURLOPT_SSL_VERIFYPEER, false);
    //Set remote URL
    curl_easy_setopt(curl, CURLOPT_URL, endpoint.c_str());

    std::string params;
    for(std::unordered_map<std::string,std::string>::iterator it = parameters.begin(); it != parameters.end(); ++it)
    {
        params = it->first + ": " + it->second + " ";
        headers = curl_slist_append(headers, (const char *)params.c_str());
    }

    curl_easy_setopt(curl, CURLOPT_POSTFIELDS, jsonObject.c_str());
    CURLcode res = curl_easy_setopt(curl, CURLOPT_HTTPHEADER, headers);

    curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, ResponseRecievedCallback);

    res = curl_easy_perform(curl);
    curl_easy_getinfo(curl, CURLINFO_RESPONSE_CODE, &httpCode);

//Uncommenting this line makes my application crash

    //curl_easy_cleanup(curl);
}

但是,當我添加此行時,我的統一應用崩潰,並出現以下異常:

 Receiving unhandled NULL exception
Obtained 13 stack frames.
#0  0x000001207a4438 in Curl_expire_clear
#1  0x00000120790e25 in Curl_close

我花了幾天的時間在線尋找一些解決方案,閱讀了curl文檔,但找不到任何幫助。 如果有人能解釋為什么會崩潰,我將不勝感激。

非常感謝!

通過將httpCode設置為long而不是int(根據文檔)來解決此問題。 我以前一定忽略了它!

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM