curl-library
Memory leak in a libcurl with mbedtls
Date: Thu, 17 Mar 2016 14:44:36 +0200
Hello
Valgrind is reporting memory leaks in libcurl when it is used with a mbedtls
Currently I am running:
*curl 7.47.1 (x86_64-pc-linux-gnu) libcurl/7.47.1 mbedTLS/2.2.1 zlib/1.2.8
c-ares/1.10.0*
*Protocols: file http https *
*Features: AsynchDNS IPv6 Largefile SSL libz UnixSockets*
Here is an out put log
My test code is:
/* <DESC>
* Simple HTTPS GET
* </DESC>
*/
#include <stdio.h>
#include <curl/curl.h>
int main(void)
{
CURL *curl;
CURLcode res;
curl_global_init(CURL_GLOBAL_DEFAULT);
curl = curl_easy_init();
if(curl) {
curl_easy_setopt(curl, CURLOPT_URL, "https://example.com/");
/* set the cert for client authentication */
curl_easy_setopt(curl, CURLOPT_SSLCERT, "test_cert.pem");
/* set the private key (file or ID in engine) */
curl_easy_setopt(curl, CURLOPT_SSLKEY, "test_key.pem");
curl_easy_setopt(curl, CURLOPT_KEYPASSWD, NULL);
curl_easy_setopt(curl, CURLOPT_SSL_VERIFYPEER, 1);
curl_easy_setopt(curl, CURLOPT_SSL_VERIFYHOST, 1L);
res = curl_easy_perform(curl);
/* Check for errors */
if(res != CURLE_OK)
fprintf(stderr, "curl_easy_perform() failed: %s\n",
curl_easy_strerror(res));
/* always cleanup */
curl_easy_cleanup(curl);
}
curl_global_cleanup();
return 0;
}
*Test data: test_cert.pem: *
-----BEGIN CERTIFICATE-----
MIIDRTCCAi2gAwIBAgIGDPpgvFFcMA0GCSqGSIb3DQEBBQUAMGgxCzAJBgNVBAYT
Ak5OMTEwLwYDVQQKDChFZGVsIEN1cmwgQXJjdGljIElsbHVkaXVtIFJlc2VhcmNo
IENsb3VkMSYwJAYDVQQDDB1Ob3J0aGVybiBOb3doZXJlIFRydXN0IEFuY2hvcjAe
Fw0xNTAzMjExNTA3MTFaFw0yMzA2MDcxNTA3MTFaMFcxCzAJBgNVBAYTAk5OMTEw
LwYDVQQKDChFZGVsIEN1cmwgQXJ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eQhrGUpCcqi3J6riQIDAQAB
AoGAK7nYD+TVV0rw3mdeEJo+JBivTRqnRX2BNuj4uvf4rZOV7adl6SN6Mu05HSzZ
TUXL+KOx60FQzFnox2lr9QzRU/LelLQ3H9fgVTVmGUCEAoDVRoWas8XlYGZsiHZ/
yJn+9Z3yQYpufSb0LQiSt73sgrTNPu50gMxe/ZSAbSscyyECQQDV8juKzWmizlTh
+wVs/pihE0+BX1BRCsezs7FCdDEWle3XidBtYlYyUIm5wx6v8xM/F7Q/nwgymOnV
A62PtfyjAkEAzsM3DsuJ9dG5n+EPTH3kDdfr0eYy76XPYz4HK8/FgiKPWy55BRCH
biLcbDAe06olJiCzEvwggFigthrIqj0t4wJBALDTUi74c3SiADn+FI/vJQsMQMv2
kRVKSZ/WxozcJ645IKjiOKgPfJp9QjeMcxKNXrzoxItIz6eyBqGONqbujO0CQQCh
b6azdJR5TJEklfL+BGVlsas8rgIjP1FX6Xxr5sQNwbIwvW5cV/WGNs3n4wKOvZBX
3rwzHIy76XdB+FOpKC+FAkBDVbicC19LE6+tBzOyx4uTEm3N7N8vh566VaOpok02
Io7F/WYL7WSCXAtvmueWV+FJyVUMN1f2nWfWqaEXP2ag
-----END RSA PRIVATE KEY-----
*The Valgrind output log is: *
==2036==
==2036== HEAP SUMMARY:
==2036== in use at exit: 944 bytes in 10 blocks
==2036== total heap usage: 20,749 allocs, 20,739 frees, 1,956,063 bytes
allocated
==2036==
==2036== 24 bytes in 1 blocks are definitely lost in loss record 2 of 10
==2036== at 0x4C2CC70: calloc (in
/usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==2036== by 0x505B29B: ssl_append_key_cert (in
/home/mindaugas/.../mbedtls-2.2.1/install/lib/libmbedtls.so.10)
==2036== by 0x40D7E4: mbedtls_connect_common (in
/home/mindaugas/.../curl-7.47.1/docs/examples/https)
==2036== by 0x40BC02: Curl_ssl_connect_nonblocking (in
/home/mindaugas/.../curl-7.47.1/docs/examples/https)
==2036== by 0x411AFC: Curl_http_connect (in
/home/mindaugas/.../curl-7.47.1/docs/examples/https)
==2036== by 0x41BF14: Curl_protocol_connect (in
/home/mindaugas/.../curl-7.47.1/docs/examples/https)
==2036== by 0x407C45: multi_runsingle (in
/home/mindaugas/.../curl-7.47.1/docs/examples/https)
==2036== by 0x408718: curl_multi_perform (in
/home/mindaugas/.../curl-7.47.1/docs/examples/https)
==2036== by 0x4039BA: curl_easy_perform (in
/home/mindaugas/.../curl-7.47.1/docs/examples/https)
==2036== by 0x40348E: main (in
/home/mindaugas/.../curl-7.47.1/docs/examples/https)
==2036==
==2036== 920 (336 direct, 584 indirect) bytes in 1 blocks are definitely
lost in loss record 10 of 10
==2036== at 0x4C2CC70: calloc (in
/usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==2036== by 0x54B06CF: rsa_alloc_wrap (in
/home/mindaugas/.../mbedtls-2.2.1/install/lib/libmbedcrypto.so.0)
==2036== by 0x54AFFC3: mbedtls_pk_setup (in
/home/mindaugas/.../mbedtls-2.2.1/install/lib/libmbedcrypto.so.0)
==2036== by 0x54B2F5B: mbedtls_pk_parse_key (in
/home/mindaugas/.../mbedtls-2.2.1/install/lib/libmbedcrypto.so.0)
==2036== by 0x54B3288: mbedtls_pk_parse_keyfile (in
/home/mindaugas/.../mbedtls-2.2.1/install/lib/libmbedcrypto.so.0)
==2036== by 0x40D0F3: mbedtls_connect_common (in
/home/mindaugas/.../curl-7.47.1/docs/examples/https)
==2036== by 0x40BC02: Curl_ssl_connect_nonblocking (in
/home/mindaugas/.../curl-7.47.1/docs/examples/https)
==2036== by 0x411AFC: Curl_http_connect (in
/home/mindaugas/.../curl-7.47.1/docs/examples/https)
==2036== by 0x41BF14: Curl_protocol_connect (in
/home/mindaugas/.../curl-7.47.1/docs/examples/https)
==2036== by 0x407C45: multi_runsingle (in
/home/mindaugas/.../curl-7.47.1/docs/examples/https)
==2036== by 0x408718: curl_multi_perform (in
/home/mindaugas/.../curl-7.47.1/docs/examples/https)
==2036== by 0x4039BA: curl_easy_perform (in
/home/mindaugas/.../curl-7.47.1/docs/examples/https)
==2036==
==2036== *LEAK SUMMARY*:
==2036== definitely lost: 360 bytes in 2 blocks
==2036== indirectly lost: 584 bytes in 8 blocks
==2036== possibly lost: 0 bytes in 0 blocks
==2036== still reachable: 0 bytes in 0 blocks
==2036== suppressed: 0 bytes in 0 blocks
==2036==
==2036== For counts of detected and suppressed errors, rerun with: -v
==2036== ERROR SUMMARY: 2 errors from 2 contexts (suppressed: 0 from 0)
-------------------------------------------------------------------
List admin: https://cool.haxx.se/list/listinfo/curl-library
Etiquette: https://curl.haxx.se/mail/etiquette.html
Received on 2016-03-17