设置CURLOPT_HTTPHEADER后,我可以立即调用curl_slist_free_all吗?

bug*_*oaf 3 c libcurl

我可以这样做吗?

curl_easy_setopt(curl, CURLOPT_HTTPHEADER, headerlist);
curl_slist_free_all(headerlist);
Run Code Online (Sandbox Code Playgroud)

也就是说,我可以在发送请求之前释放标题列表吗?卷曲会复制吗?

muk*_*nda 6

不.在源代码中,setopt函数只保存指针.

case CURLOPT_HTTPHEADER:
    /*
     * Set a list with HTTP headers to use (or replace internals with)
     */
    data->set.headers = va_arg(param, struct curl_slist *);
    break;
Run Code Online (Sandbox Code Playgroud)