fixing a memory leak
authorTobias Brunner <tobias@strongswan.org>
Tue, 11 Nov 2008 09:56:47 +0000 (09:56 -0000)
committerTobias Brunner <tobias@strongswan.org>
Tue, 11 Nov 2008 09:56:47 +0000 (09:56 -0000)
src/charon/plugins/kernel_netlink/kernel_netlink_ipsec.c
src/charon/plugins/kernel_pfkey/kernel_pfkey_ipsec.c

index d0c9b72..6832222 100644 (file)
@@ -1756,6 +1756,7 @@ static bool add_bypass_policies()
 {
        int fd, family, port;
        enumerator_t *sockets;
+       bool status = TRUE;
        
        /* we open an AF_KEY socket to autoload the af_key module. Otherwise
         * setsockopt(IPSEC_POLICY) won't work. */
@@ -1797,17 +1798,20 @@ static bool add_bypass_policies()
                {
                        DBG1(DBG_KNL, "unable to set IPSEC_POLICY on socket: %s",
                                 strerror(errno));
-                       return FALSE;
+                       status = FALSE;
+                       break;
                }
                policy.sadb_x_policy_dir = IPSEC_DIR_INBOUND;
                if (setsockopt(fd, sol, ipsec_policy, &policy, sizeof(policy)) < 0)
                {
                        DBG1(DBG_KNL, "unable to set IPSEC_POLICY on socket: %s", 
                                 strerror(errno));
-                       return FALSE;
+                       status = FALSE;
+                       break;
                }
        }
-       return TRUE;
+       sockets->destroy(sockets);
+       return status;
 }
 
 /*
index 1f2c651..313642f 100644 (file)
@@ -1879,6 +1879,7 @@ static bool add_bypass_policies(private_kernel_pfkey_ipsec_t *this)
 {
        int fd, family, port;
        enumerator_t *sockets;
+       bool status = TRUE;
        
        sockets = charon->socket->create_enumerator(charon->socket);
        while (sockets->enumerate(sockets, &fd, &family, &port))
@@ -1910,17 +1911,20 @@ static bool add_bypass_policies(private_kernel_pfkey_ipsec_t *this)
                {
                        DBG1(DBG_KNL, "unable to set IPSEC_POLICY on socket: %s",
                                 strerror(errno));
-                       return FALSE;
+                       status = FALSE;
+                       break;
                }
                policy.sadb_x_policy_dir = IPSEC_DIR_INBOUND;
                if (setsockopt(fd, sol, ipsec_policy, &policy, sizeof(policy)) < 0)
                {
                        DBG1(DBG_KNL, "unable to set IPSEC_POLICY on socket: %s", 
                                 strerror(errno));
-                       return FALSE;
+                       status = FALSE;
+                       break;
                }
        }
-       return TRUE;
+       sockets->destroy(sockets);
+       return status;
 }
 
 /*