Freeing memory when in a loop
Ken Hornstein
kenh at cmf.nrl.navy.mil
Thu Nov 9 11:08:26 EST 2006
>The following code is in a loop, running periodically to see if
>Credential needs to be renewed (a lot of code is left out to make this
>easier to peruse):
>[...]
> free( principalName );
> free( cursor );
> krb5_free_creds( context, &curCred );
I don't believe you can call free() on cursor ... it might contain
stuff that points to other items (although it seems that in the file
cache case, it does not). I thought the only way to free a cursor was
to call krb5_cc_end_seq_get() (which you do down below, so I'm
surprised there isn't something complaining about a double-free).
> if (( ! code ))
> {
> krb5_free_creds( context, &myCreds );
> krb5_free_principal( context, tgs );
> krb5_free_principal( context, principal );
> krb5_free_context( context );
> }
I think, no matter what ... you want to at least free myCreds, don't you?
And if you're calling krb5_init_context again, then you want to always
free it.
>What would be a good recommendation on a Kerberos programming book that
>would cover this topic?
Sigh, I think we're all in the wilderness here. It looks like you've got
most of it, though.
--Ken
More information about the Kerberos
mailing list