提交 52d43ff7 编写于 作者: G Greg Kurz 提交者: Michael Roth

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: NGreg Kurz <groug@kaod.org>
Reviewed-by: NStefan Hajnoczi <stefanha@redhat.com>
(cherry picked from commit 21328e1e)
Signed-off-by: NGreg Kurz <gkurz@linux.vnet.ibm.com>
Signed-off-by: NMichael Roth <mdroth@linux.vnet.ibm.com>
上级 e103f9e7
...@@ -356,10 +356,15 @@ static int local_open(FsContext *ctx, V9fsPath *fs_path, ...@@ -356,10 +356,15 @@ static int local_open(FsContext *ctx, V9fsPath *fs_path,
{ {
char *buffer; char *buffer;
char *path = fs_path->data; char *path = fs_path->data;
int fd;
buffer = rpath(ctx, path); buffer = rpath(ctx, path);
fs->fd = open(buffer, flags | O_NOFOLLOW); fd = open(buffer, flags | O_NOFOLLOW);
g_free(buffer); g_free(buffer);
if (fd == -1) {
return -1;
}
fs->fd = fd;
return fs->fd; return fs->fd;
} }
...@@ -368,13 +373,15 @@ static int local_opendir(FsContext *ctx, ...@@ -368,13 +373,15 @@ static int local_opendir(FsContext *ctx,
{ {
char *buffer; char *buffer;
char *path = fs_path->data; char *path = fs_path->data;
DIR *stream;
buffer = rpath(ctx, path); buffer = rpath(ctx, path);
fs->dir.stream = opendir(buffer); stream = opendir(buffer);
g_free(buffer); g_free(buffer);
if (!fs->dir.stream) { if (!stream) {
return -1; return -1;
} }
fs->dir.stream = stream;
return 0; return 0;
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册