misc memory leaks
authorKen Raeburn <raeburn@mit.edu>
Fri, 27 Jun 2008 02:47:06 +0000 (02:47 +0000)
committerKen Raeburn <raeburn@mit.edu>
Fri, 27 Jun 2008 02:47:06 +0000 (02:47 +0000)
Fix various memory leaks that show up mostly in error cases (e.g.,
failure to allocate one small object, and then we forget to free
another one).

ticket: new
target_version: 1.6.4
tags: pullup

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

src/kdc/do_tgs_req.c
src/kdc/kdc_util.c
src/lib/gssapi/krb5/k5seal.c
src/lib/krb5/krb/bld_pr_ext.c
src/lib/krb5/krb/get_creds.c
src/lib/krb5/krb/get_in_tkt.c
src/lib/krb5/krb/init_ctx.c
src/lib/krb5/os/an_to_ln.c
src/lib/rpc/auth_gss.c
src/plugins/kdb/db2/adb_policy.c

index 0b263d0dcbf45e0218a53b6c35c6816c214e2af0..ae25eb41c7bbc6746bbf253928301057e07f9f11 100644 (file)
@@ -57,7 +57,7 @@ krb5_error_code
 process_tgs_req(krb5_data *pkt, const krb5_fulladdr *from,
                krb5_data **response)
 {
-    krb5_keyblock * subkey;
+    krb5_keyblock * subkey = 0;
     krb5_kdc_req *request = 0;
     krb5_db_entry server;
     krb5_kdc_rep reply;
@@ -99,8 +99,10 @@ process_tgs_req(krb5_data *pkt, const krb5_fulladdr *from,
     /*
      * setup_server_realm() sets up the global realm-specific data pointer.
      */
-    if ((retval = setup_server_realm(request->server)))
+    if ((retval = setup_server_realm(request->server))) {
+       krb5_free_kdc_req(kdc_context, request);
        return retval;
+    }
 
     fromstring = inet_ntop(ADDRTYPE2FAMILY(from->address->addrtype),
                           from->address->contents,
@@ -711,7 +713,9 @@ cleanup:
     if (session_key.contents)
        krb5_free_keyblock_contents(kdc_context, &session_key);
     if (newtransited)
-       free(enc_tkt_reply.transited.tr_contents.data); 
+       free(enc_tkt_reply.transited.tr_contents.data);
+    if (subkey)
+       krb5_free_keyblock(kdc_context, subkey);
 
     return retval;
 }
@@ -833,6 +837,7 @@ find_alternate_tgs(krb5_kdc_req *request, krb5_db_entry *server,
                       "TGS_REQ: issuing TGT %s", sname);
                free(sname);
            }
+           krb5_free_realm_tree(kdc_context, plist);
            return;
        }
        krb5_db_free_principal(kdc_context, server, *nprincs);
index 869eb189694fd6479401771d2bd81029f3cba210..4b2ce474e440fa3e3215dcbd2b8573de479fbfa3 100644 (file)
@@ -1,7 +1,7 @@
 /*
  * kdc/kdc_util.c
  *
- * Copyright 1990,1991,2007 by the Massachusetts Institute of Technology.
+ * Copyright 1990,1991,2007,2008 by the Massachusetts Institute of Technology.
  * All Rights Reserved.
  *
  * Export of this software from the United States of America may
@@ -418,6 +418,10 @@ kdc_get_server_key(krb5_ticket *ticket, krb5_keyblock **key, krb5_kvno *kvno)
        retval = krb5_dbekd_decrypt_key_data(kdc_context, &master_keyblock,
                                             server_key,
                                             *key, NULL);
+       if (retval) {
+           free(*key);
+           *key = NULL;
+       }
     } else
        retval = ENOMEM;
 errout:
index 4557194faa6c59e5b62c0820609e4b2193f04840..edd3319e88859a8a516c0b64875857949ab2c599 100644 (file)
@@ -159,8 +159,10 @@ make_seal_token_v1 (krb5_context context,
     }
 
     code = krb5_c_checksum_length(context, md5cksum.checksum_type, &sumlen);
-    if (code)
+    if (code) {
+      xfree(t);
       return(code);
+    }
     md5cksum.length = sumlen;
 
 
index c1af72616acca00c9fbc25eb31b6180d6fca458f..c7236b7b5a80d68c0dc34249281068e975b04432 100644 (file)
@@ -1,7 +1,7 @@
 /*
  * lib/krb5/krb/bld_pr_ext.c
  *
- * Copyright 1991 by the Massachusetts Institute of Technology.
+ * Copyright 1991, 2008 by the Massachusetts Institute of Technology.
  * All Rights Reserved.
  *
  * Export of this software from the United States of America may
@@ -39,7 +39,7 @@ krb5_build_principal_ext(krb5_context context,  krb5_principal * princ,
     register int i, count = 0;
     register unsigned int size;
     register char *next;
-    char *tmpdata;
+    char *tmpdata = 0;
     krb5_data *princ_data;
     krb5_principal princ_ret;
 
@@ -97,6 +97,7 @@ free_out:
        krb5_xfree(princ_data[i].data);
     krb5_xfree(princ_data);
     krb5_xfree(princ_ret);
+    krb5_xfree(tmpdata);
     va_end(ap);
     return ENOMEM;
 }
index b3e94f4c61709dca15422f33d0cf3bab976aedef..38c3383170f6b245723c67e52568b83e53c4aee6 100644 (file)
@@ -1,7 +1,7 @@
 /*
  * lib/krb5/krb/get_creds.c
  *
- * Copyright 1990 by the Massachusetts Institute of Technology.
+ * Copyright 1990, 2008 by the Massachusetts Institute of Technology.
  * All Rights Reserved.
  *
  * Export of this software from the United States of America may
@@ -207,8 +207,12 @@ krb5_get_credentials_val_renew_core(krb5_context context, krb5_flags options,
            retval = 255;
            break;
     }
-    if (retval) return retval;
+    /*
+     * Callers to krb5_get_cred_blah... must free up tgts even in
+     * error cases.
+     */
     if (tgts) krb5_free_tgt_creds(context, tgts);
+    if (retval) return retval;
 
     retval = krb5_cc_get_principal(context, ccache, &tmp);
     if (retval) return retval;
index 8f4f57a13bf44e2fd2e3e3ade9d8ec00b2c2a77c..a993870ced08725789100545e4a9980073ec3f4d 100644 (file)
@@ -1059,13 +1059,15 @@ krb5_get_init_creds(krb5_context context,
 
        /* stuff the client realm into the server principal.
           realloc if necessary */
-       if (request.server->realm.length < request.client->realm.length)
-           if ((request.server->realm.data =
-                (char *) realloc(request.server->realm.data,
-                                 request.client->realm.length)) == NULL) {
+       if (request.server->realm.length < request.client->realm.length) {
+           char *p = realloc(request.server->realm.data,
+                             request.client->realm.length);
+           if (p == NULL) {
                ret = ENOMEM;
                goto cleanup;
            }
+           request.server->realm.data = p;
+       }
 
        request.server->realm.length = request.client->realm.length;
        memcpy(request.server->realm.data, request.client->realm.data,
index e29557066183f2a9c70461ea117c3877d703ec69..3ebbb908dd5d342af122209872d6a275450a3100 100644 (file)
@@ -359,8 +359,10 @@ get_profile_etype_list(krb5_context context, krb5_enctype **ktypes, char *profst
        
        if ((old_ktypes =
             (krb5_enctype *)malloc(sizeof(krb5_enctype) * (count + 1))) ==
-           (krb5_enctype *) NULL)
+           (krb5_enctype *) NULL) {
+           profile_release_string(retval);
            return ENOMEM;
+       }
        
        sp = retval;
        j = 0;
index d04b85cdb71624d968dc64e3e7973597571a7257..6e6dadc570271df7e25797e017043e8cdf52da71 100644 (file)
@@ -1,7 +1,7 @@
 /*
  * lib/krb5/os/an_to_ln.c
  *
- * Copyright 1990,1991,2007 by the Massachusetts Institute of Technology.
+ * Copyright 1990,1991,2007,2008 by the Massachusetts Institute of Technology.
  * All Rights Reserved.
  *
  * Export of this software from the United States of America may
@@ -438,7 +438,7 @@ aname_replacer(char *string, char **contextp, char **result)
                    memset(out, '\0', MAX_FORMAT_BUFFER);
                    if (!do_replacement(rule, repl, doglobal, in, out)) {
                        free(rule);
-                   free(repl);
+                       free(repl);
                        kret = KRB5_LNAME_NOTRANS;
                        break;
                    }
@@ -453,6 +453,7 @@ aname_replacer(char *string, char **contextp, char **result)
                }
                else {
                    /* No memory for copies */
+                   free(rule);
                    kret = ENOMEM;
                    break;
                }
index d11c5e267d065a6cc0c8dfdec8f2c7efdd72475c..1debd4d69c673763c2c786a23e9826b8eabfc389 100644 (file)
@@ -186,6 +186,7 @@ authgss_create(CLIENT *clnt, gss_name_t name, struct rpc_gss_sec *sec)
                        rpc_createerr.cf_stat = RPC_SYSTEMERROR;
                        rpc_createerr.cf_error.re_errno = ENOMEM;
                        free(auth);
+                       free(gd);
                        return (NULL);
                }
        }
index e338cbbd022437054ecc4bb6c78dc3a7d466e8a0..04cc48970a3cc888b651380b9753e9f191e7abcd 100644 (file)
@@ -358,6 +358,7 @@ osa_adb_iter_policy(osa_adb_policy_t db, osa_adb_iter_policy_func func,
        if(!xdr_osa_policy_ent_rec(&xdrs, entry)) {
            xdr_destroy(&xdrs);
            free(aligned_data);
+           osa_free_policy_ent(entry);
            ret = OSA_ADB_FAILURE;
            goto error;
        }