This is an automated email from the git hooks/post-receive script.

git pushed a commit to branch master
in repository efl.

View the commit online.

commit 5db00cca5f66bac7ccaf5b5cae59b065c031f99f
Author: Cedric BAIL <[email protected]>
AuthorDate: Wed Nov 11 21:00:20 2026 -0600

    ecore_con: the http dialer lets go of the fd handler it keeps for curl
    
    The dialer makes one Efl.Loop.Fd per connection for libcurl with
    efl_add_ref(), which gives the dialer a reference of its own on top of
    the parent's. When curl dropped the socket, efl_del() only released the
    parent's, so every connection that ran left an object behind. The
    reference is now released with the delete when the dialer still held it,
    and straight away when there is no dialer to hold it.
    
    A GET against a server on this machine is added to the suite. It passes
    whether or not the leak is there: the regression check is this case run
    under valgrind, where the three definite leaks through the curlm socket
    callback are gone.
    
    Co-Authored-By: Claude Opus 5.5 <[email protected]>
---
 src/lib/ecore_con/efl_net_dialer_http.c            | 14 +++-
 src/tests/ecore_con/ecore_con_test_ecore_con_url.c | 97 ++++++++++++++++++++++
 2 files changed, 109 insertions(+), 2 deletions(-)

diff --git a/src/lib/ecore_con/efl_net_dialer_http.c b/src/lib/ecore_con/efl_net_dialer_http.c
index 0b183953ee..0147d0c1ab 100644
--- a/src/lib/ecore_con/efl_net_dialer_http.c
+++ b/src/lib/ecore_con/efl_net_dialer_http.c
@@ -443,10 +443,19 @@ _efl_net_dialer_http_curlm_socket_manage(CURL *e, curl_socket_t fd, int what, vo
 
    if (what == CURL_POLL_REMOVE)
      {
-        if ((pd) && (pd->fdhandler == fdhandler))
+        /* The dialer owns the extra reference efl_add_ref() gave, as long as
+         * it still points at the handler; efl_del() only drops the parent's
+         * reference, so the dialer's has to go too or the handler leaks. */
+        Eina_Bool owned = (pd) && (pd->fdhandler == fdhandler);
+
+        if (owned)
           pd->fdhandler = NULL;
         curl_multi_assign(cm->multi, fd, NULL);
-        if (fdhandler) efl_del(fdhandler);
+        if (fdhandler)
+          {
+             efl_del(fdhandler);
+             if (owned) efl_unref(fdhandler);
+          }
      }
    else
      {
@@ -461,6 +470,7 @@ _efl_net_dialer_http_curlm_socket_manage(CURL *e, curl_socket_t fd, int what, vo
                                      efl_loop_fd_set(efl_added, fd));
              EINA_SAFETY_ON_NULL_RETURN_VAL(fdhandler, -1);
              if (pd) pd->fdhandler = fdhandler;
+             else efl_unref(fdhandler); /* no dialer to own the extra ref */
              curl_multi_assign(cm->multi, fd, fdhandler);
              flags = 0;
           }
diff --git a/src/tests/ecore_con/ecore_con_test_ecore_con_url.c b/src/tests/ecore_con/ecore_con_test_ecore_con_url.c
index fd4b6e9ca9..1fc3e16629 100644
--- a/src/tests/ecore_con/ecore_con_test_ecore_con_url.c
+++ b/src/tests/ecore_con/ecore_con_test_ecore_con_url.c
@@ -433,8 +433,105 @@ EFL_START_TEST(ecore_con_test_ecore_con_url_cookies_ignore_session)
 }
 EFL_END_TEST
 
+/* A request answered by a server on this machine runs to its end. Under
+ * valgrind this is what shows whether the dialer lets go of everything it
+ * made for the connection: the fd handler it keeps for libcurl used to be
+ * left behind with an extra reference when curl dropped the socket. */
+typedef struct _Local_Http Local_Http;
+
+struct _Local_Http
+{
+   Ecore_Con_Server *server;
+   int status;
+   Eina_Bool done;
+};
+
+static Eina_Bool
+_local_http_client_data(void *data EINA_UNUSED, int type EINA_UNUSED, void *event_info)
+{
+   Ecore_Con_Event_Client_Data *ev = event_info;
+   static const char answer[] =
+     "HTTP/1.1 200 OK\r\nContent-Length: 2\r\nConnection: close\r\n\r\nok";
+
+   ecore_con_client_send(ev->client, answer, sizeof(answer) - 1);
+   ecore_con_client_flush(ev->client);
+   return ECORE_CALLBACK_PASS_ON;
+}
+
+static Eina_Bool
+_local_http_client_del(void *data EINA_UNUSED, int type EINA_UNUSED, void *event_info)
+{
+   Ecore_Con_Event_Client_Del *ev = event_info;
+
+   if (ev->client) ecore_con_client_del(ev->client);
+   return ECORE_CALLBACK_PASS_ON;
+}
+
+static Eina_Bool
+_local_http_complete(void *data, int type EINA_UNUSED, void *event_info)
+{
+   Local_Http *lh = data;
+   Ecore_Con_Event_Url_Complete *ev = event_info;
+
+   lh->status = ev->status;
+   lh->done = EINA_TRUE;
+   ecore_main_loop_quit();
+   return ECORE_CALLBACK_PASS_ON;
+}
+
+static Eina_Bool
+_local_http_deadline(void *data EINA_UNUSED)
+{
+   ecore_main_loop_quit();
+   return ECORE_CALLBACK_CANCEL;
+}
+
+EFL_START_TEST(ecore_con_test_ecore_con_url_local_get)
+{
+   Local_Http lh = { NULL, 0, EINA_FALSE };
+   Ecore_Event_Handler *h[3];
+   Ecore_Timer *deadline;
+   Ecore_Con_Url *url;
+   char link[64];
+   int port;
+
+   fail_if(ecore_con_url_init() != 1);
+
+   for (port = 38300; (port < 38400) && !lh.server; port++)
+     {
+        lh.server = ecore_con_server_add(ECORE_CON_REMOTE_TCP, "127.0.0.1", port, NULL);
+     }
+   fail_if(!lh.server);
+   port--;
+
+   h[0] = ecore_event_handler_add(ECORE_CON_EVENT_CLIENT_DATA, _local_http_client_data, NULL);
+   h[1] = ecore_event_handler_add(ECORE_CON_EVENT_CLIENT_DEL, _local_http_client_del, NULL);
+   h[2] = ecore_event_handler_add(ECORE_CON_EVENT_URL_COMPLETE, _local_http_complete, &lh);
+
+   snprintf(link, sizeof(link), "http://127.0.0.1:%d/", port);
+   url = ""
+   fail_if(!url);
+   fail_if(!ecore_con_url_get(url));
+
+   deadline = ecore_timer_add(10.0, _local_http_deadline, NULL);
+   ecore_main_loop_begin();
+   if (lh.done) ecore_timer_del(deadline);
+
+   fail_if(!lh.done);
+   fail_if(lh.status != 200);
+
+   ecore_con_url_free(url);
+   ecore_event_handler_del(h[0]);
+   ecore_event_handler_del(h[1]);
+   ecore_event_handler_del(h[2]);
+   ecore_con_server_del(lh.server);
+   fail_if(ecore_con_url_shutdown() != 0);
+}
+EFL_END_TEST
+
 void ecore_con_test_ecore_con_url(TCase *tc)
 {
+   tcase_add_test(tc, ecore_con_test_ecore_con_url_local_get);
    tcase_add_test(tc, ecore_con_test_ecore_con_url_init);
    tcase_add_test(tc, ecore_con_test_ecore_con_url_create);
    tcase_add_test(tc, ecore_con_test_ecore_con_url_download);

-- 
To stop receiving notification emails like this one, please contact
the administrator of this repository.

Reply via email to