Coding practices proposals

Ken Raeburn raeburn at MIT.EDU
Thu Mar 17 23:44:43 EDT 2011


Minor editorial (I think) points:

On Mar 17, 2011, at 17:33, ghudson at MIT.EDU wrote:
> 1. When transferring ownership of a pointer (such as when returning an
> allocated value to a caller via an output parameter), null out the old
> owner pointer unless it is immediately going out of scope.

... or being freed?  (E.g., if the old owning reference lives in a structure that gets freed on the next line.)

> 3. Initialize variables containing owner pointers to NULL.  Free them
> in the function's cleanup handler, even if it would be possible to
> free them sooner.

If you take "free them" to mean "call the appropriate 'free' function", as I did on first reading, this means, "even if in some code paths you do free them sooner".  But if you take "free them" to mean "perform the call that actually releases the storage", then the above description seems to discourage doing it any sooner, "even if it would be possible".  I think the former is the better approach.

Ken



More information about the krbdev mailing list