proper semantics for returning a character string?
Robert P. J. Day
rpjday at mindspring.com
Thu Apr 20 20:36:13 UTC 2006
On Thu, 20 Apr 2006, Natanael Copa wrote:
> On Thu, 20 Apr 2006 12:17:18 -0400 (EDT)
> "Robert P. J. Day" <rpjday at mindspring.com> wrote:
>
> > On Thu, 20 Apr 2006, Jason Schoon wrote:
> >
> > > You have a nice potential for memory leakage using this approach.
> > > If this is a routine called numerous times without exiting the
> > > application, you will slowly be losing all that dynamically
> > > allocated space.
> >
> > it occurs to me to ask what happens if you try mapping a UID to a
> > username numerous times using the standard library routines.
> >
> > i'm assuming you would use:
> >
> > struct passwd *getpwuid(uid_t uid);
> >
> > right? this would give you a dynamically-allocated "struct passwd",
> > out of which you would extract the username. so far, so good.
> >
> > but what happens to that "struct passwd" space? i'm assuming it
> > stays around as well so that, if you call that routine a thousand
> > times with the same UID, you'll get a thousand "passwd struct"s
> > lying around, even though it's the same UID each time, is that
> > correct?
>
> no. the space get overwritten second time. The code is not re-entrant.
>
> The return value may point to static area, and may be overwritten by
> subsequent calls to getpwent(), getpwnam(), or getpwuid().
>
> Please, please, I don't want to be the only one reading the manuals.
easy. i read exactly that same sentence and what i see is that it
says that the return value ***may*** point to static area, and
***may*** be overwritten by subsequent calls.
that's not the same as saying that it *is* static and *will* be
overwritten. would someone like to clarify this?
rday
More information about the busybox
mailing list