簡體   English   中英

為什么libcurl在清除調用之后仍然留下可訪問的塊?

[英]Why libcurl still leaves reachable blocks after cleanup calls?

我一直在使用libcurl來處理獲取/發布請求,並且valgrind總是向我顯示相同數量的可訪問塊(21)。 我在標准cURL的配置中缺少什么來避免這種情況?

這是帶有“錯誤”的最簡單的代碼:

#include <stdio.h>
#include <stdlib.h>
#include <curl/curl.h>

int main(int argc, char const *argv[]) {

  CURL *curl;

  curl_global_init(CURL_GLOBAL_ALL);
  curl = curl_easy_init();
  ·
  ·
  ·
  curl_easy_cleanup(curl);
  curl_global_cleanup();

  return 0;

}

我編譯

$ gcc -o test cURL.c -lcurl

Valgrind檢查

$ valgrind --leak-check=full --track-origins=yes ./test

==4295== Memcheck, a memory error detector
==4295== Copyright (C) 2002-2017, and GNU GPL'd, by Julian Seward et al.
==4295== Using Valgrind-3.13.0 and LibVEX; rerun with -h for copyright info
==4295== Command: ./test
==4295== 
==4295== 
==4295== HEAP SUMMARY:
==4295==     in use at exit: 858 bytes in 21 blocks
==4295==   total heap usage: 4,265 allocs, 4,244 frees, 185,353 bytes allocated
==4295== 
==4295== LEAK SUMMARY:
==4295==    definitely lost: 0 bytes in 0 blocks
==4295==    indirectly lost: 0 bytes in 0 blocks
==4295==      possibly lost: 0 bytes in 0 blocks
==4295==    still reachable: 858 bytes in 21 blocks
==4295==         suppressed: 0 bytes in 0 blocks
==4295== Reachable blocks (those to which a pointer was found) are not shown.
==4295== To see them, rerun with: --leak-check=full --show-leak-kinds=all
==4295== 
==4295== For counts of detected and suppressed errors, rerun with: -v
==4295== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 0 from 0)

libcurl鏈接許多庫,其中一些庫沒有curl_global_cleanup類的函數來恢復初始化並釋放所有內存。 當libcurl與NSS鏈接以獲得TLS支持以及libssh2及其對libgcrypt的使用時,就會發生這種情況。 在這方面,將GNUTLS作為TLS實現較為干凈。

通常,這不是問題,因為這些輔助庫僅用於在進程終止時釋放內存的操作系統,因此不需要顯式清理(甚至會減慢進程終止)。 僅對於某些內存調試器,清除清理例程的效果是可見的,並且valgrind通過區分實際的泄漏(沒有指針的內存)和在進程終止時仍可訪問的內存來處理這種情況(因此可以如果進程尚未終止,請再次使用)。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM