【问题标题】:curl curl_global_init memory leakcurl curl_global_init 内存泄漏
【发布时间】:2014-12-09 09:16:11
【问题描述】:
#include <curl/curl.h>
#include <mcheck.h>

int main(int argc, char** argv) 
{   
    setenv("MALLOC_TRACE", "output", 1);
    mtrace();
    curl_global_init(CURL_GLOBAL_ALL);
    curl_global_cleanup();
    return 0;
}

gcc -o test test.c -lcurl

./测试

mtrace 输出

 - 0x000000000154f010 Free 6293 was never alloc'd 0x7f9a4e515256
 - 0x000000000154f040 Free 6294 was never alloc'd 0x7f9a4e4a299d
 - 0x000000000154f060 Free 6295 was never alloc'd 0x7f9a4e51540c

 Memory not freed:

Address     Size     Caller

0x000000000154f830    0x258  at 0x7f9a4d303134

0x000000000154fa90     0xb0  at 0x7f9a4d303134

0x000000000154fb50     0x80  at 0x7f9a4d303134

0x000000000154fbe0     0x18  at 0x7f9a4d303134

0x0000000001568ca0     0x20  at 0x7f9a4d303134

0x0000000001568cd0     0x20  at 0x7f9a4d303134

什么可能导致这种内存泄漏?

【问题讨论】:

    标签: curl mtrace


    【解决方案1】:

    迟到的答案,但我自己也遇到了同样的问题。 如果 libcurl 与 openssl 支持链接,您必须手动释放 openssl 资源。

    #include "openssl/conf.h"
    #include "openssl/err.h"
    #include "openssl/engine.h"
    #include "openssl\ssl.h"
    
    CONF_modules_free();
    ERR_remove_state(0);
    ENGINE_cleanup();
    CONF_modules_unload(1);
    ERR_free_strings();
    EVP_cleanup();
    CRYPTO_cleanup_all_ex_data();
    sk_SSL_COMP_free(SSL_COMP_get_compression_methods()); 
    

    帮我搞定了

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-12-28
      • 2011-05-28
      • 2012-03-02
      • 1970-01-01
      • 1970-01-01
      • 2011-10-08
      • 2013-01-20
      • 2011-10-31
      相关资源
      最近更新 更多