proper semantics for returning a character string?
Robert P. J. Day
rpjday at mindspring.com
Thu Apr 20 20:16:00 UTC 2006
On Thu, 20 Apr 2006, Tito wrote:
> char *map_uid_to_username(int uid) {
> struct passwd *pwd;
> pwd = getpwuid(uid;
> if (pwd) return pwd->pw_name;
> bb_error_msg("uknown uid %d", uid);
> return NULL;
> }
>
> The return value may point to static area (when?), and may be
> overwritten by
> subsequent calls to getpwent(), getpwnam(), or getpwuid().
>
> So in this case no memory leak?
>
> Tito
i'm not sure. the way i read the man page, when you call getpwuid(),
you have no control over how it's allocating the space for the
resulting structure so that routine really *could* be allocating a new
one on every call, no? i don't see how you can control that.
in any event, see my recently-posted proposal.
rday
More information about the busybox
mailing list