diff mbox

[2/3] qemu-bridge-helper: Reverse return value setting logic in parse_acl_file

Message ID dadb5dde09c4a6c41596782706e8b9f308aaccc1.1496132443.git.mprivozn@redhat.com (mailing list archive)
State New, archived
Headers show

Commit Message

Michal Privoznik May 30, 2017, 8:23 a.m. UTC
Just like in the previous commit, it's better to have just a
single point of exit from a function as we can have cleanup code
just once instead of copying it all over the place.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
---
 qemu-bridge-helper.c | 13 +++++++------
 1 file changed, 7 insertions(+), 6 deletions(-)
diff mbox

Patch

diff --git a/qemu-bridge-helper.c b/qemu-bridge-helper.c
index af6613ea18..a7f9bf06cc 100644
--- a/qemu-bridge-helper.c
+++ b/qemu-bridge-helper.c
@@ -65,6 +65,7 @@  static int parse_acl_file(const char *filename, ACLList *acl_list)
     FILE *f;
     char line[4096];
     ACLRule *acl_rule;
+    int ret = -1;
 
     f = fopen(filename, "r");
     if (f == NULL) {
@@ -92,9 +93,8 @@  static int parse_acl_file(const char *filename, ACLList *acl_list)
 
         if (arg == NULL) {
             fprintf(stderr, "Invalid config line:\n  %s\n", line);
-            fclose(f);
             errno = EINVAL;
-            return -1;
+            goto cleanup;
         }
 
         *arg = 0;
@@ -132,15 +132,16 @@  static int parse_acl_file(const char *filename, ACLList *acl_list)
             parse_acl_file(arg, acl_list);
         } else {
             fprintf(stderr, "Unknown command `%s'\n", cmd);
-            fclose(f);
             errno = EINVAL;
-            return -1;
+            goto cleanup;
         }
     }
 
-    fclose(f);
+    ret = 0;
 
-    return 0;
+ cleanup:
+    fclose(f);
+    return ret;
 }
 
 static bool has_vnet_hdr(int fd)