[Openvpn-devel,v1] route: close socket in Haiku get_default_gateway()

Message ID 20261102165927.110589-1-frank@lichtenheld.com
State New
Headers
Series [Openvpn-devel,v1] route: close socket in Haiku get_default_gateway() |

Commit Message

Frank Lichtenheld Nov. 2, 2026, 4:59 p.m. UTC
  From: Razvan Cojocaru <razvanc@mailbox.org>

The socket used for the routing table ioctls was never closed. Close
it on the early returns and right after the last ioctl.

Broken since 7da14925 ("Haiku: Add calls to manage routing table").

Change-Id: Ia0304e5ef5f8a553262a32d78ed21577973ee2e9
Signed-off-by: Razvan Cojocaru <razvanc@mailbox.org>
Acked-by: Frank Lichtenheld <frank@lichtenheld.com>
Gerrit URL: https://gerrit.openvpn.net/c/openvpn/+/2093
---

This change was reviewed on Gerrit and approved by at least one
developer. I request to merge it to master.

Gerrit URL: https://gerrit.openvpn.net/c/openvpn/+/2093
This mail reflects revision 1 of this Change.

Acked-by according to Gerrit (reflected above):
Frank Lichtenheld <frank@lichtenheld.com>
  

Comments

Gert Doering Nov. 2, 2026, 9:32 p.m. UTC | #1
Interesting find ;-)

Not tested beyond "looks reasonable"...

Your patch has been applied to the master and release/2.7 branch (bugfix).

commit e9ecd3c6ded76c03b9d74c1b37c87a07b54e10e6 (master)
Author: Razvan Cojocaru
Date:   Mon Nov 2 17:59:27 2026 +0100

     route: close socket in Haiku get_default_gateway()

     Signed-off-by: Razvan Cojocaru <razvanc@mailbox.org>
     Acked-by: Frank Lichtenheld <frank@lichtenheld.com>
     Gerrit URL: https://gerrit.openvpn.net/c/openvpn/+/2093
     Message-Id: <20261102165927.110589-1-frank@lichtenheld.com>
     URL: https://lore.kernel.org/openvpn-devel/20261102165927.110589-1-frank@lichtenheld.com
     Signed-off-by: Gert Doering <gert@greenie.muc.de>


--
kind regards,

Gert Doering
  

Patch

diff --git a/src/openvpn/route.c b/src/openvpn/route.c
index 0bce966..e8de2d5 100644
--- a/src/openvpn/route.c
+++ b/src/openvpn/route.c
@@ -3719,12 +3719,14 @@ 
     if (ioctl(sockfd, SIOCGRTSIZE, &config, sizeof(struct ifconf)) < 0)
     {
         msg(M_ERRNO, "%s: Error getting routing table size", __func__);
+        close(sockfd);
         return;
     }
 
     uint32 size = (uint32)config.ifc_value;
     if (size == 0)
     {
+        close(sockfd);
         return;
     }
 
@@ -3733,7 +3735,9 @@ 
 
     config.ifc_len = size;
     config.ifc_buf = buffer;
-    if (ioctl(sockfd, SIOCGRTTABLE, &config, sizeof(struct ifconf)) < 0)
+    int ret = ioctl(sockfd, SIOCGRTTABLE, &config, sizeof(struct ifconf));
+    close(sockfd);
+    if (ret < 0)
     {
         free(buffer);
         return;