Freeing memory when in a loop

Keagle, Chuck chuck.keagle at boeing.com
Thu Nov 9 16:47:59 EST 2006


In the LDAP world there is the book referred to as the LDAP Bible,
"Understanding and Developing LDAP Directory Services."

When looking on the net, I see "Kerberos: The Definitive Guide",
"Kerberos: A Network Authentication System", "Hundestammvater Und
Kerberos", and "Iseries Access for Windows V5r2 Hot topics".  I'm
thinking the first two might help get ones feet wet.  Which seems better
to most?

Thanks for pointing out the double free possibility.  I hadn't picked up
on it yet and removed the free(cursor) call in an inner loop to let
krb5_cc_end_seq_get() take care of it after having been used more than
once depending on how many cached entries there are.  My original intent
was that it needed to be done after each use.

----
Not all who wander are lost.

                          |     ----  ___o  |  chuck.keagle at boeing.com
Chuck Keagle              |  -------  \ <,  |  Work:  (425) 865-1488
Enterprise Servers:  HPC  |  ----- ( )/ ( ) |  Cell:  (425) 417-3434
http://card.web.boeing.com/Webcard.cfm?id=73990
 

> -----Original Message-----
> From: Ken Hornstein [mailto:kenh at cmf.nrl.navy.mil] 
> Sent: Thursday, November 09, 2006 8:08 AM
> To: Keagle, Chuck
> Cc: kerberos at mit.edu
> Subject: Re: Freeing memory when in a loop 
> 
> >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