qemu-devel@nongnu.org
[Top] [All Lists]

Re: [Qemu-devel] [PATCH] [REPOST] Simplily linux-user/path.c

Subject: Re: [Qemu-devel] [PATCH] [REPOST] Simplily linux-user/path.c
From: Thiemo Seufer
Date: Fri, 23 Feb 2007 16:58:56 +0000
Kirill A. Shutemov wrote:
> Fixed version of the patch in the attacment. Please, comment.
[snip]
>  /* Look for path in emulation dir, otherwise return name. */
>  const char *path(const char *name)
>  {
> +    char *newname = (char *) alloca(strlen(pref)+strlen(name)+1);
> +    struct stat buf;
>      /* Only do absolute paths: quick and dirty, but should mostly be OK.
>         Could do relative by tracking cwd. */
> -    if (!base || name[0] != '/')
> -     return name;
> +    if (!pref || name[0] != '/')
> +        return name;
> +
> +    strcpy(newname,pref);
> +    strcat(newname,name);
>  
> -    return follow_path(base, name) ?: name;
> +    return stat(newname,&buf) ? name : strdup(newname);
>  }

This leaks memory allocated by strdup(). Also, the old code tries to
avoid syscalls by memorizing the paths. AFAICS we should do some
caching here.


Thiemo


_______________________________________________
Qemu-devel mailing list
Qemu-devel@xxxxxxxxxx
http://lists.nongnu.org/mailman/listinfo/qemu-devel

<Prev in Thread] Current Thread [Next in Thread>