小编Fet*_*bes的帖子

如何清洁卷发手柄?

我有以下示例源代码,允许使用 libcurl 发送 HTTP 请求。

我注意到大量内存使用。使用 valgrind 调试显示内存泄漏。即使我用过curl_easy_cleanup()。我也使用过curl_easy_reset()curl_global_cleanup()但它们根本没有任何效果,并且内存泄漏仍然存在。

我需要知道如何通过 libcurl 释放分配的内存。

下面是启动和清理 libcurl 的基本简单源代码。

int main()
{
    CURL* pEasy = NULL;  

    pEasy = curl_easy_init();

    if (pEasy != NULL)
    {
        curl_easy_setopt(pEasy, CURLOPT_USERNAME, "test");
        curl_easy_setopt(pEasy, CURLOPT_PASSWORD, "test");
        curl_easy_setopt(pEasy, CURLOPT_URL, "http:/192.168.22.217:3000");

        curl_easy_perform(pEasy);

        curl_easy_cleanup(pEasy);
    }
 }
Run Code Online (Sandbox Code Playgroud)

Valgrind 显示该程序的内存泄漏。

找到下面的 valgrind 输出

 sudo valgrind --leak-check=full --show-leak-kinds=all ./mem
==7215== Memcheck, a memory error detector
==7215== Copyright (C) 2002-2015, and GNU GPL'd, by Julian Seward et al.
==7215== Using Valgrind-3.11.0 and …
Run Code Online (Sandbox Code Playgroud)

c c++ curl memory-leaks libcurl

4
推荐指数
1
解决办法
3176
查看次数

标签 统计

c ×1

c++ ×1

curl ×1

libcurl ×1

memory-leaks ×1