curl / Mailing Lists / curl-library / Single Mail
Buy commercial curl support. We help you work out your issues, debug your libcurl applications, use the API, port to new platforms, add new features and more. With a team lead by the curl founder Daniel himself.

How to properly re-use an easy handle having CURLOPT_CONNECT_ONLY=1?

From: Aleksander Mazur via curl-library <curl-library_at_lists.haxx.se>
Date: Tue, 14 Jan 2025 02:05:46 +0100

Hi,

I'm trying to monitor an inbox using IMAP. I'd like to let cURL do the TLS and
authentication magic. The program must deal with connection terminated by
server or disrupted after some time. So I tried to follow man curl_easy_perform:
> You can do any amount of calls to curl_easy_perform(3) while using the same
> easy_handle.

The problem is that although everything seems to work (in version 8.9.1),
valgrind reports massive memory leaks each time the easy handle is re-used by
curl_easy_perform. On the other hand, if interrupted right after first
successful connection, memleak report is clear.

Therefore I wrote simplest possible program to demonstrate the problem and run
it against development version of libcurl. It should login and then logout 10x.
However, talking to a locally running test IMAP server (from cURL test suite):
$ tests/ftpserver.pl --verbose --port 43143 --proto imap --logdir /tmp/imap

... it connects successfully just once. Second time libcurl aborts with:
example: url.c:749: Curl_conn_seems_dead: Assertion `!data->conn' failed.

When using a real-world server with TLS (imaps://...), it also aborts when
trying to re-use the handle, but somewhere else:
example: multi.c:964: Curl_attach_connection: Assertion `!data->conn' failed.

The TLS case differs also by extra "* Expire cleared" message.
Haven't found additional hints in man curl_easy_send / curl_easy_recv.
Changing CURLOPT_MAXCONNECTS doesn't help.
Please review attached source code and let me know what's wrong.
Thanks,
-- 
Aleksander Mazur




-- 
Unsubscribe: https://lists.haxx.se/mailman/listinfo/curl-library
Etiquette:   https://curl.se/mail/etiquette.html
Received on 2025-01-14