diff options
| author | Yukihiro "Matz" Matsumoto <[email protected]> | 2013-11-13 14:44:02 +0900 |
|---|---|---|
| committer | Yukihiro "Matz" Matsumoto <[email protected]> | 2013-11-13 14:44:02 +0900 |
| commit | 08e6bd47a02e2dbaf3d96f385caee102f95a26a1 (patch) | |
| tree | 15c88adc6d9695297ab4006bddaf119cf1174760 /tools | |
| parent | ca704e54383cc7180edbe84b081de83e868aa7c6 (diff) | |
| download | mruby-08e6bd47a02e2dbaf3d96f385caee102f95a26a1.tar.gz mruby-08e6bd47a02e2dbaf3d96f385caee102f95a26a1.zip | |
fclose input file
Diffstat (limited to 'tools')
| -rw-r--r-- | tools/mrbc/mrbc.c | 12 |
1 files changed, 9 insertions, 3 deletions
diff --git a/tools/mrbc/mrbc.c b/tools/mrbc/mrbc.c index df64d6b7d..27e151ad2 100644 --- a/tools/mrbc/mrbc.c +++ b/tools/mrbc/mrbc.c @@ -187,6 +187,7 @@ load_file(mrb_state *mrb, struct mrbc_args *args) mrb_value result; char *input = args->argv[args->idx]; FILE *infile; + int need_close = FALSE; c = mrbc_context_new(mrb); if (args->verbose) @@ -195,17 +196,22 @@ load_file(mrb_state *mrb, struct mrbc_args *args) if (input[0] == '-' && input[1] == '\0') { infile = stdin; } - else if ((infile = fopen(input, "r")) == NULL) { - fprintf(stderr, "%s: cannot open program file. (%s)\n", args->prog, input); - return mrb_nil_value(); + else { + need_close = TRUE; + if ((infile = fopen(input, "r")) == NULL) { + fprintf(stderr, "%s: cannot open program file. (%s)\n", args->prog, input); + return mrb_nil_value(); + } } mrbc_filename(mrb, c, input); args->idx++; if (args->idx < args->argc) { + need_close = FALSE; mrbc_partial_hook(mrb, c, partial_hook, (void*)args); } result = mrb_load_file_cxt(mrb, infile, c); + if (need_close) fclose(infile); if (mrb_undef_p(result) || mrb_fixnum(result) < 0) { mrbc_context_free(mrb, c); return mrb_nil_value(); |
