[13337] in Athena Bugs
decmips 7.7H: hesiod
daemon@ATHENA.MIT.EDU (Greg Hudson)
Sat Mar 18 13:55:43 1995
To: bugs@MIT.EDU
Cc: netbsd-dev@MIT.EDU, linux-dev@MIT.EDU
Date: Sat, 18 Mar 1995 13:53:45 EST
From: Greg Hudson <ghudson@MIT.EDU>
System name: maze
Type and version: KN02ca 7.7H (1 update(s) to same version)
Display type: PMAG-DV
What were you trying to do?
Use hes_getpwnam().
What's wrong:
hes_resolve() allocates memory for each string in its return
vector using calloc(). hes_getpwcommon() in hespwnam.c copies
the first return vector value into a buffer, but never frees
it. Thus, repeated invocations of hes_getpwnam() result in
leaked memory.
What should have happened:
The hesiod(3) man page should document that each returned
string should be freed with free() after use.
hes_getpwcommon() should be modified to free the string
returned by hes_resolve, e.g.:
*** hespwnam.c.old Sat Mar 18 13:49:35 1995
--- hespwnam.c Sat Mar 18 13:48:21 1995
***************
*** 37,42 ****
--- 37,43 ----
return(NULL);
/* choose only the first response (only 1 expected) */
(void) strcpy(buf, pp[0]);
+ free(pp[0]);
p = buf;
pw_entry.pw_name = p;
p = _NextPWField(p);
Please describe any relevant documentation references:
Not exactly a documentation reference, but the following test
program illustrates the problem:
#include <hesiod.h>
#include <pwd.h>
int main(int argc, char **argv)
{
struct passwd *ent;
int i;
for (i = 0; i < atoi(argv[1]); i++)
ent = hes_getpwnam("ghudson");
printf("Done.\n");
while (1);
}
To reproduce the problem, compile this program against the
hesiod libraries and run it first with a small argument like
10, and then with a large argument like 10000. Each time,
use ps to see the size of the process after it prints "Done".
You should find that 10000 invocations leaks about a megabyte
of memory.