Trying to get to the bottom of the /root/.cvsignore problem which lots of
people seem to be complaining about...
The comments associated with get_homedir() seem to already hint at a
solution, but it has never been implemented. Looking at the function, I note
the following:
Function get_homedir() in file 'cvs-1.10.8/src/filesubr.c':
char *
get_homedir ()
{
static char *home = NULL;
char *env = getenv ("HOME");
struct passwd *pw;
if (home != NULL)
return home;
if (env)
home = env;
else if ((pw = (struct passwd *) getpwuid (getuid ()))
&& pw->pw_dir)
home = xstrdup (pw->pw_dir);
else
return 0;
return home;
}
1) No caller of get_homedir() seems to free the returned string. Is this
correct?
2) char *env - does getenv() return a malloc'ed string? man pages suggest
no, so this seems OK
3) struct passwd *pw - does getpwuid() return (ptr. to) a malloc'ed struct?
man pages suggest YES, so this looks buggy.
4) xstrdup() returns a malloc'ed string; this will never be freed if (1) is
true.
Therefore, the only way this will currently run OK is if HOME is set (which
I guess is usually the case).
I guess the solution would be to ensure that the string returned is always a
malloc'ed string, and then the caller always frees this string. Therefore a
modified version of get_homedir() could be something like:
char *
get_homedir ()
{
char *home = NULL;
char *env = getenv ("HOME");
struct passwd *pw;
if (env)
home = xstrdup (env);
else if (pw = (struct passwd *) getpwuid (getuid ()))
{
if (pw->pw_dir)
home = xstrdup (pw->pw_dir);
free (pw); /* assuming it is malloc'ed in getpwuid() */
}
return home;
}
I apologise if I am flouting any conventions here as I have never posted any
bugs to GNU before.
Robert Cragie
Design Engineer
Jennic Ltd.
Sheffield Science Park
Sheffield
S1 2NS
United Kingdom
Tel: (+44) 114 281 2655
Fax: (+44) 114 281 2951
mailto:[EMAIL PROTECTED]