]> git.ipfire.org Git - thirdparty/krb5.git/commitdiff
plug the leak in set_names, and add an unset_names function so we can
authorMarc Horowitz <marc@mit.edu>
Tue, 6 Oct 1998 06:37:59 +0000 (06:37 +0000)
committerMarc Horowitz <marc@mit.edu>
Tue, 6 Oct 1998 06:37:59 +0000 (06:37 +0000)
plug other leaks

git-svn-id: svn://anonsvn.mit.edu/krb5/branches/marc-3des@10963 dc483132-0cff-0310-8789-dd5450dbe970

src/lib/rpc/svc_auth_gssapi.c

index 2a3233ee9302a94430e7e706dce9d7a09a44dc0b..df59859f0d2a18222da13ea894a601714ceae03b 100644 (file)
@@ -887,7 +887,7 @@ done:
 }
 
 /*
- * Function: _svcauth_gssapi_set_name
+ * Function: _svcauth_gssapi_set_names
  *
  * Purpose: Sets the list of service names for which incoming
  * authentication requests should be honored.
@@ -916,6 +916,13 @@ bool_t _svcauth_gssapi_set_names(names, num)
      if (server_name_list == NULL)
          goto fail;
      
+     for (i = 0; i < num; i++) {
+         server_name_list[i] = 0;
+         server_creds_list[i] = 0;
+     }
+
+     server_creds_count = num;
+     
      for (i = 0; i < num; i++) {
          in_buf.value = names[i].name;
          in_buf.length = strlen(in_buf.value) + 1;
@@ -939,19 +946,41 @@ bool_t _svcauth_gssapi_set_names(names, num)
          }
      }
 
-     server_creds_count = num;
-     
      return TRUE;
 
 fail:
-     /* memory leak: not releasing names/creds already acquired */
-     if (server_creds_list)
+     _svcauth_gssapi_unset_names();
+
+     return FALSE;
+}
+
+/* Function: _svcauth_gssapi_unset_names
+ *
+ * Purpose: releases the names and credentials allocated by
+ * _svcauth_gssapi_set_names
+ */
+
+void _svcauth_gssapi_unset_names()
+{
+     int i;
+     OM_uint32 minor_stat;
+
+     if (server_creds_list) {
+         for (i = 0; i < server_creds_count; i++)
+              if (server_creds_list[i])
+                   gss_release_cred(&minor_stat, &server_creds_list[i]);
          free(server_creds_list);
-     if (server_name_list)
+     }
+
+     if (server_name_list) {
+         for (i = 0; i < server_creds_count; i++)
+              if (server_name_list[i])
+                   gss_release_name(&minor_stat, &server_name_list[i]);
          free(server_name_list);
-     return FALSE;
+     }
 }
 
+
 /*
  * Function: _svcauth_gssapi_set_log_badauth_func
  *