9pfs: remove side-effects in local_open() and local_opendir()

If these functions fail, they should not change *fs. Let's use local
variables to fix this.

Signed-off-by: Greg Kurz <groug@kaod.org>
Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com>
stable-2.9
Greg Kurz 2017-02-26 23:41:55 +01:00
parent 00c90bd1c2
commit 21328e1e57
1 changed files with 10 additions and 3 deletions

View File

@ -356,10 +356,15 @@ static int local_open(FsContext *ctx, V9fsPath *fs_path,
{
char *buffer;
char *path = fs_path->data;
int fd;
buffer = rpath(ctx, path);
fs->fd = open(buffer, flags | O_NOFOLLOW);
fd = open(buffer, flags | O_NOFOLLOW);
g_free(buffer);
if (fd == -1) {
return -1;
}
fs->fd = fd;
return fs->fd;
}
@ -368,13 +373,15 @@ static int local_opendir(FsContext *ctx,
{
char *buffer;
char *path = fs_path->data;
DIR *stream;
buffer = rpath(ctx, path);
fs->dir.stream = opendir(buffer);
stream = opendir(buffer);
g_free(buffer);
if (!fs->dir.stream) {
if (!stream) {
return -1;
}
fs->dir.stream = stream;
return 0;
}