proper semantics for returning a character string?

Robert P. J. Day rpjday at mindspring.com
Thu Apr 20 16:17:18 UTC 2006


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?

if that's true, then even the *standard* semantics for this operation
have the potential for memory leakage, no?

rday



More information about the busybox mailing list