使用 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 解决了这个问题(根据文档)。我一定是之前忽略了它!