简体   繁体   中英

Memory leak when using curl_easy_setopt

I have the following code:

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();
}

If I call

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

and then

curl_easy_reset(curl)

and then

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

again, does the allocated memory in the first curl_easy_setopt get freed by curl_easy_reset(curl) or by the second call of curl_easy_setopt ?

Or the memory is not freed and there is a memory leak?

Does the allocated memory in the first curl_easy_setopt() get freed by curl_easy_reset(curl) or by the second call to curl_easy_setopt() ?

The thing is that:

  1. It's an implementation detail.

  2. Arising from the preceding fact, it does not/should not matter. Either one is true, proper memory management is possible in both cases.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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