繁体   English   中英

使用curl_easy_setopt时内存泄漏

[英]Memory leak when using curl_easy_setopt

我有以下代码:

CURL *curl;

void http_init()
{
    curl = curl_easy_init();
    if (!curl) return -1;
}

void http_send_message(char *msg_out, char **msg_in)
{
    CURLcode res;

    curl_easy_setopt(curl, CURLOPT_URL, "http://192.168.1.133:8080/tawtaw");
    curl_easy_setopt(curl, CURLOPT_USERNAME, "tawtaw");
    curl_easy_setopt(curl, CURLOPT_PASSWORD, "tawtaw");
    curl_easy_setopt(curl, CURLOPT_HTTPAUTH, CURLAUTH_BASIC|CURLAUTH_DIGEST);
        .
        .
        .
   curl_easy_reset(curl); 
}

void http_exit()
{
    curl_easy_cleanup(curl); 
}

int main()
{
   char *msgin=NULL;
   http_init();
   http_send_message("message number 1", &msg_in);
   free(msgin);msgin=NULL;
   http_send_message("message number 2", &msg_in);
   free(msgin);msgin=NULL;
   http_exit();
}

如果我打电话

curl_easy_setopt(curl, CURLOPT_URL, "http://192.168.1.133:8080/tawtaw");

接着

curl_easy_reset(curl)

接着

curl_easy_setopt(curl, CURLOPT_URL, "http://192.168.1.133:8080/tawtaw");

再次,第一个curl_easy_setopt分配的内存是由curl_easy_reset(curl)还是第二次调用curl_easy_setopt

或者内存没有释放,内存泄漏?

第一个curl_easy_setopt()分配的内存是由curl_easy_reset(curl)释放还是第二次调用curl_easy_setopt()

问题在于:

  1. 这是一个实现细节。

  2. 由于前面的事实,它没有/不应该重要。 任何一个都是真的,在这两种情况下都可以进行适当的内存管理。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM