curl-library
Leak when sending multipart/form-data repeatedly
Date: Tue, 19 Dec 2017 13:31:25 -0300
Hi everyone, I'm testing the following program (replace URL by something real):
#include <stddef.h>
#include "curl/curl.h"
#define URL "http://some-url.com/test"
static void send_request(CURL *const curl)
{
curl_easy_reset(curl);
curl_mime *const mime = curl_mime_init(curl);
if (mime != NULL)
{
long int code;
curl_mimepart *const part = curl_mime_addpart(mime);
if (part != NULL &&
curl_mime_name(part, "file") == CURLE_OK &&
curl_mime_filedata(part, "content.json") == CURLE_OK &&
curl_easy_setopt(curl, CURLOPT_URL, URL) == CURLE_OK &&
curl_easy_setopt(curl, CURLOPT_MIMEPOST, mime) == CURLE_OK &&
curl_easy_perform(curl) == CURLE_OK &&
curl_easy_getinfo(curl, CURLINFO_RESPONSE_CODE, &code) == CURLE_OK)
{
printf("Status code: %ld\n", code);
}
else
{
puts("Error when building request");
}
curl_mime_free(mime);
}
else
{
puts("Error when building MIME");
}
}
int main(void)
{
CURL *const curl = curl_easy_init();
if (curl != NULL)
{
send_request(curl);
send_request(curl);
curl_easy_cleanup(curl);
}
else
{
puts("Error when building curl handle");
}
return 0;
}
When I run this, Valgrind shows the following:
==29988==
==29988== HEAP SUMMARY:
==29988== in use at exit: 96,832 bytes in 3,228 blocks
==29988== total heap usage: 4,215 allocs, 987 frees, 346,064 bytes allocated
==29988==
==29988== 176 (32 direct, 144 indirect) bytes in 1 blocks are definitely lost in loss record 567 of 617
==29988== at 0x4C2FB0F: malloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==29988== by 0x4E7CDF8: curl_domalloc (memdebug.c:175)
==29988== by 0x4E924A7: Curl_slist_append_nodup (slist.c:66)
==29988== by 0x4EABFF3: Curl_mime_add_header (mime.c:1554)
==29988== by 0x4EAC0C2: add_content_type (mime.c:1568)
==29988== by 0x4EAC5AF: Curl_mime_prepare_headers (mime.c:1710)
==29988== by 0x4E537ED: Curl_http (http.c:1967)
==29988== by 0x4E83852: multi_do (multi.c:1242)
==29988== by 0x4E84665: multi_runsingle (multi.c:1652)
==29988== by 0x4E856F3: curl_multi_perform (multi.c:2162)
==29988== by 0x4E787DE: easy_transfer (easy.c:683)
==29988== by 0x4E78A1D: easy_perform (easy.c:769)
==29988==
==29988== LEAK SUMMARY:
==29988== definitely lost: 32 bytes in 1 blocks
==29988== indirectly lost: 144 bytes in 1 blocks
==29988== possibly lost: 0 bytes in 0 blocks
==29988== still reachable: 96,656 bytes in 3,226 blocks
==29988== suppressed: 0 bytes in 0 blocks
==29988== Reachable blocks (those to which a pointer was found) are not shown.
==29988== To see them, rerun with: --leak-check=full --show-leak-kinds=all
==29988==
==29988== For counts of detected and suppressed errors, rerun with: -v
==29988== ERROR SUMMARY: 1 errors from 1 contexts (suppressed: 0 from 0)
I'm concerned about the lost blocks here. Am I missing a cleanup?
-------------------------------------------------------------------
Unsubscribe: https://cool.haxx.se/list/listinfo/curl-library
Etiquette: https://curl.haxx.se/mail/etiquette.html
Received on 2017-12-19