diff options
| author | Yukihiro Matsumoto <[email protected]> | 2012-07-14 07:39:50 +0900 |
|---|---|---|
| committer | Yukihiro Matsumoto <[email protected]> | 2012-07-14 07:39:50 +0900 |
| commit | 59389561715aed3b37d571e34c0c80f17f192788 (patch) | |
| tree | dc8d253175099a3ed22e081c32dd7f6d1b6523a6 /tools | |
| parent | e3806922245c15ff9417ca4513c9052ebfa40021 (diff) | |
| download | mruby-59389561715aed3b37d571e34c0c80f17f192788.tar.gz mruby-59389561715aed3b37d571e34c0c80f17f192788.zip | |
mrbc: better cleanup before exit
Diffstat (limited to 'tools')
| -rw-r--r-- | tools/mrbc/mrbc.c | 28 |
1 files changed, 12 insertions, 16 deletions
diff --git a/tools/mrbc/mrbc.c b/tools/mrbc/mrbc.c index a121eaa0e..428a3b781 100644 --- a/tools/mrbc/mrbc.c +++ b/tools/mrbc/mrbc.c @@ -144,12 +144,13 @@ parse_args(mrb_state *mrb, int argc, char **argv, struct _args *args) } static void -cleanup(struct _args *args) +cleanup(mrb_state *mrb, struct _args *args) { if (args->rfp) fclose(args->rfp); if (args->wfp) fclose(args->wfp); + mrb_close(mrb); } int @@ -168,9 +169,8 @@ main(int argc, char **argv) n = parse_args(mrb, argc, argv, &args); if (n < 0 || args.rfp == NULL) { - cleanup(&args); + cleanup(mrb, &args); usage(argv[0]); - mrb_close(mrb); return n; } @@ -179,16 +179,14 @@ main(int argc, char **argv) c->dump_result = 1; c->no_exec = 1; result = mrb_load_file_cxt(mrb, args.rfp, c); - if (mrb_undef_p(result)) { - cleanup(&args); - mrb_close(mrb); - return -1; + if (mrb_undef_p(result) || mrb_fixnum(result) < 0) { + cleanup(mrb, &args); + return EXIT_FAILURE; } - n = mrb_fixnum(result); - if (n < 0 || args.check_syntax) { - cleanup(&args); - mrb_close(mrb); - return n; + if (args.check_syntax) { + printf("Syntax OK\n"); + cleanup(mrb, &args); + return EXIT_SUCCESS; } if (args.initname) { if (args.dump_type == DUMP_TYPE_BIN) @@ -200,10 +198,8 @@ main(int argc, char **argv) n = mrb_dump_irep(mrb, n, args.wfp); } - cleanup(&args); - mrb_close(mrb); - - return n; + cleanup(mrb, &args); + return EXIT_SUCCESS; } void |
