Fix a memory leak (unlikely to happen in practice) in krb5_mcc_store;
authorGreg Hudson <ghudson@mit.edu>
Tue, 10 Feb 2009 17:17:39 +0000 (17:17 +0000)
committerGreg Hudson <ghudson@mit.edu>
Tue, 10 Feb 2009 17:17:39 +0000 (17:17 +0000)
use a cleanup handler for robustness.

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

src/lib/krb5/ccache/cc_memory.c

index 2cfd60a10c7718e7502cb79f86d9440f9d51e880..61ab5451b534e9604dbe92d59fee8befe1708c87 100644 (file)
@@ -643,18 +643,19 @@ krb5_mcc_store(krb5_context ctx, krb5_ccache id, krb5_creds *creds)
     if (new_node == NULL)
        return ENOMEM;
     err = krb5_copy_creds(ctx, creds, &new_node->creds);
-    if (err) {
-       free(new_node);
-       return err;
-    }
+    if (err)
+       goto cleanup;
     err = k5_cc_mutex_lock(ctx, &mptr->lock);
     if (err)
-       return err;
+       goto cleanup;
     new_node->next = mptr->link;
     mptr->link = new_node;
     update_mcc_change_time(mptr);
     k5_cc_mutex_unlock(ctx, &mptr->lock);
     return 0;
+cleanup:
+    free(new_node);
+    return err;
 }
 
 static krb5_error_code KRB5_CALLCONV