> From: Gary Winiger <gww at eng.sun.com>
> > Bart Blanquart wrote:
> > > On 02/25/09 22:09, Scott Rotondo wrote:
> > >  > Bart Blanquart wrote:
> > >  >> Current webrev at http://cr.opensolaris.org/~bartbl/6251549-20090225/
> > >  >
> > >  > This is OK, but it would also work fine if you get rid of strdup() and
> > >  > the corresponding free() at line 136.
> > > 
> > > Yeah, but that makes things more fragile. A later call to getpw*() could 
> > > change the username being processed.
> > 
> > Since we know the only such calls in this program are in get_username(), 
> > I would get rid of the strdup(). However, I don't feel strongly enough 
> > to insist on this point.
> 
>       I feel a lot stronger than Scott on this point.  IMO, it is misleading
>       to future maintainers.  It also overly complicates the code, again
>       misleading future maintainers.

I'd take this as a matter of style.  To me, the interface as defined is
much simpler for future maintainers:  rather than returning a static
value which the caller is responsible for protecting against calls to
getpw*(), it returns a string which the caller is responsible for
deallocating.  The latter model strikes me as simpler to describe and
enforce.

                                        -JZ

Reply via email to