Remember and close the kadmin socket we opened
authorGreg Hudson <ghudson@mit.edu>
Fri, 26 Aug 2011 17:56:44 +0000 (17:56 +0000)
committerGreg Hudson <ghudson@mit.edu>
Fri, 26 Aug 2011 17:56:44 +0000 (17:56 +0000)
Prior to ticket #6746, the RPC library opened the kadmin socket and
took responsibility for closing.  When we added IPv6 support, the
calling code became the owner of the socket but wasn't closing it,
resulting in a file descriptor leak.

ticket: 6949

git-svn-id: svn://anonsvn.mit.edu/krb5/trunk@25115 dc483132-0cff-0310-8789-dd5450dbe970

src/lib/kadm5/clnt/client_init.c
src/lib/kadm5/clnt/client_internal.h

index d6309979ffe0a0b4286fe3f019c20e5a591009b7..a1d20fb7e0c4ba3ee52f835e77537f92b104e22b 100644 (file)
@@ -155,7 +155,7 @@ init_any(krb5_context context, char *client_name, enum init_type init_type,
          kadm5_config_params *params_in, krb5_ui_4 struct_version,
          krb5_ui_4 api_version, char **db_args, void **server_handle)
 {
-    int fd;
+    int fd = -1;
 
     krb5_boolean iprop_enable;
     int port;
@@ -192,6 +192,7 @@ init_any(krb5_context context, char *client_name, enum init_type init_type,
     handle->struct_version = struct_version;
     handle->api_version = api_version;
     handle->clnt = 0;
+    handle->client_socket = -1;
     handle->cache_name = 0;
     handle->destroy_cache = 0;
     handle->context = 0;
@@ -301,7 +302,9 @@ init_any(krb5_context context, char *client_name, enum init_type init_type,
 #endif
         goto error;
     }
+    handle->client_socket = fd;
     handle->lhandle->clnt = handle->clnt;
+    handle->lhandle->client_socket = fd;
 
     /* now that handle->clnt is set, we can check the handle */
     if ((code = _kadm5_check_handle((void *) handle)))
@@ -372,6 +375,8 @@ error:
         AUTH_DESTROY(handle->clnt->cl_auth);
     if(handle->clnt)
         clnt_destroy(handle->clnt);
+    if (fd != -1)
+        close(fd);
 
     kadm5_free_config_params(handle->context, &handle->params);
 
@@ -796,6 +801,8 @@ kadm5_destroy(void *server_handle)
         AUTH_DESTROY(handle->clnt->cl_auth);
     if (handle->clnt)
         clnt_destroy(handle->clnt);
+    if (handle->client_socket != -1)
+        close(handle->client_socket);
     if (handle->lhandle)
         free (handle->lhandle);
 
index c3f8999a6e0d979244060b7d9416b86d631945ba..6ee8eea2331269109d259c716dcd611b3656f39b 100644 (file)
@@ -72,6 +72,7 @@ typedef struct _kadm5_server_handle_t {
     char *          cache_name;
     int             destroy_cache;
     CLIENT *        clnt;
+    int             client_socket;
     krb5_context    context;
     kadm5_config_params params;
     struct _kadm5_server_handle_t *lhandle;