]> xenbits.xensource.com Git - qemu-xen.git/commitdiff
9pfs: remove side-effects in local_open() and local_opendir()
authorGreg Kurz <groug@kaod.org>
Sun, 26 Feb 2017 22:41:55 +0000 (23:41 +0100)
committerGreg Kurz <groug@kaod.org>
Tue, 28 Feb 2017 10:21:14 +0000 (11:21 +0100)
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>
hw/9pfs/9p-local.c

index 4a8e628117aea1f5d2dc340f653968de07c32627..607cd2aeceea70729b7faff1c5716d4e18be1eeb 100644 (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;
 }