Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: 'cd' built-in crashed zsh on a broken file system



On Tue, Jan 20, 2015 at 9:34 PM, Peter Stephenson
<p.w.stephenson@xxxxxxxxxxxx> wrote:
>
> How about this?
>
> diff --git a/Src/utils.c b/Src/utils.c
> index 4561b5e..cf18f12 100644
> --- a/Src/utils.c
> +++ b/Src/utils.c
> @@ -1108,10 +1108,13 @@ getnameddir(char *name)
>         if ((pw = getpwnam(name))) {
>             char *dir = isset(CHASELINKS) ? xsymlink(pw->pw_dir)
>                 : ztrdup(pw->pw_dir);
> -           adduserdir(name, dir, ND_USERNAME, 1);
> -           str = dupstring(dir);
> -           zsfree(dir);
> -           return str;
> +           if (dir) {
> +               adduserdir(name, dir, ND_USERNAME, 1);
> +               str = dupstring(dir);
> +               zsfree(dir);
> +               return str;
> +           } else
> +               return ztrdup(pw->pw_dir);

This ztrdup triggered a couple of errors in valgrind. Since everything
else returned from getnameddir seems to be heap allocated, should this
be dupstring instead?

-- 
Mikael Magnusson



Messages sorted by: Reverse Date, Date, Thread, Author