uci: properly close input before exit
[project/uci.git] / cli.c
diff --git a/cli.c b/cli.c
index b647f77..e1e0a66 100644 (file)
--- a/cli.c
+++ b/cli.c
@@ -305,10 +305,13 @@ static int package_cmd(int cmd, char *tuple)
                }
                if (uci_commit(ctx, &ptr.p, false) != UCI_OK) {
                        cli_perror();
+                       goto out;
                }
                break;
        case CMD_EXPORT:
-               uci_export(ctx, stdout, ptr.p, true);
+               if (uci_export(ctx, stdout, ptr.p, true) != UCI_OK) {
+                       goto out;
+               }
                break;
        case CMD_SHOW:
                if (!(ptr.flags & UCI_LOOKUP_COMPLETE)) {
@@ -333,6 +336,8 @@ static int package_cmd(int cmd, char *tuple)
                break;
        }
 
+       ret = 0;
+
 out:
        if (ptr.p)
                uci_unload(ctx, ptr.p);
@@ -682,6 +687,7 @@ int main(int argc, char **argv)
                                break;
                        case 'f':
                                if (input != stdin) {
+                                       fclose(input);
                                        perror("uci");
                                        return 1;
                                }