resource leak in gss_krb5_copy_ccache

Greg Hudson ghudson at MIT.EDU
Tue Sep 8 12:32:38 EDT 2009


On Tue, 2009-09-08 at 07:11 -0400, Morten Sylvest Olsen wrote:
> I keep getting valgrind leaks reported when I use gss_krb5_copy_ccache. 
> Looking at the code, it seems there is a krb5_free_cred_contents 
> missing. Or I may be completely off the mark?

I believe you are correct.  Can you please test out the attached patch
and see if it closes the memory leaks you're seeing without causing
other issues?

-------------- next part --------------
Index: copy_ccache.c
===================================================================
--- copy_ccache.c	(revision 22715)
+++ copy_ccache.c	(working copy)
@@ -50,8 +50,10 @@
         krb5_free_context(context);
         return(GSS_S_FAILURE);
     }
-    while (!code && !krb5_cc_next_cred(context, k5creds->ccache, &cursor, &creds))
+    while (!code && !krb5_cc_next_cred(context, k5creds->ccache, &cursor, &creds)) {
         code = krb5_cc_store_cred(context, out_ccache, &creds);
+        krb5_free_cred_contents(context, &creds);
+    }
     krb5_cc_end_seq_get(context, k5creds->ccache, &cursor);
     k5_mutex_unlock(&k5creds->lock);
     *minor_status = code;


More information about the krbdev mailing list