From: j8takagi Date: Sat, 23 Jun 2018 15:55:41 +0000 (+0900) Subject: メモリーリークの修正 X-Git-Tag: v0.4p1~11 X-Git-Url: https://j8takagi.net/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=e4b847e6ad72b23b2c65b35ae5eb3a8ee9c5b403;p=YACASL2.git メモリーリークの修正 --- diff --git a/src/casl2.c b/src/casl2.c index 237aff9..89333d5 100644 --- a/src/casl2.c +++ b/src/casl2.c @@ -122,16 +122,12 @@ asfin: */ int main(int argc, char *argv[]) { - int memsize = DEFAULT_MEMSIZE, clocks = DEFAULT_CLOCKS, opt, i, stat; + int memsize = DEFAULT_MEMSIZE, clocks = DEFAULT_CLOCKS, opt, i, stat = 0; char *af[argc], *objfile = NULL; const char *version = PACKAGE_VERSION, *cmdversion = "casl2 of YACASL2 version %s\n"; const char *usage = "Usage: %s [-slLaAtTdbvh] [-oO[]] [-M ] [-C ] FILE1[ FILE2 ...]\n"; - cerr_init(); - addcerrlist_casl2(); - addcerrlist_assemble(); - addcerrlist_exec(); /* オプションの処理 */ while((opt = getopt_long(argc, argv, "tTdslLbao::O::AM:C:vh", longopts, NULL)) != -1) { switch(opt) { @@ -189,10 +185,18 @@ int main(int argc, char *argv[]) exit(1); } } + + /* エラーの定義 */ + cerr_init(); + addcerrlist_casl2(); + addcerrlist_assemble(); + addcerrlist_exec(); + /* ソースファイルが指定されていない場合は終了 */ if(argv[optind] == NULL) { setcerr(126, ""); /* no source file */ fprintf(stderr, "CASL2 error - %d: %s\n", cerr->num, cerr->msg); + freecerr(); /* エラーの解放 */ exit(1); } reset(memsize, clocks); /* 仮想マシンCOMET IIのリセット */ diff --git a/src/comet2.c b/src/comet2.c index 73669a7..1309df9 100644 --- a/src/comet2.c +++ b/src/comet2.c @@ -32,10 +32,6 @@ int main(int argc, char *argv[]) const char *version = PACKAGE_VERSION, *cmdversion = "comet2 of YACASL2 version %s\n"; const char *usage = "Usage: %s [-btTdvh] [-M ] [-C ] FILE\n"; - cerr_init(); - addcerrlist_load(); - addcerrlist_exec(); - /* オプションの処理 */ while((opt = getopt_long(argc, argv, "tTdM:C:vh", longopts, NULL)) != -1) { switch(opt) { @@ -69,11 +65,18 @@ int main(int argc, char *argv[]) exit(1); } } + /* エラーの定義 */ + cerr_init(); + addcerrlist_load(); + addcerrlist_exec(); + if(argv[optind] == NULL) { setcerr(211, ""); /* object file not specified */ fprintf(stderr, "comet2 error - %d: %s\n", cerr->num, cerr->msg); + freecerr(); /* エラーの解放 */ exit(1); } + /* COMET II仮想マシンのリセット */ reset(memsize, clocks); execptr->start = 0; @@ -83,7 +86,6 @@ int main(int argc, char *argv[]) /* COMET II仮想マシンのシャットダウン */ shutdown(); stat = (cerr->num == 0) ? 0 : 1; - /* エラーの解放 */ - freecerr(); + freecerr(); /* エラーの解放 */ return stat; } diff --git a/src/dumpword.c b/src/dumpword.c index 1fca90e..05cfe9a 100644 --- a/src/dumpword.c +++ b/src/dumpword.c @@ -28,8 +28,6 @@ int main(int argc, char *argv[]) const char *version = PACKAGE_VERSION, *cmdversion = "dumpword of YACASL2 version %s\n"; const char *usage = "Usage: %s [-alh] WORD\n"; - cerr_init(); - addcerrlist_word(); while((opt = getopt_long(argc, argv, "alvh", longopts, NULL)) != -1) { switch(opt) { case 'l': @@ -47,18 +45,25 @@ int main(int argc, char *argv[]) } } + /* エラーの定義 */ + cerr_init(); + addcerrlist_word(); + if(argv[optind] == NULL) { fprintf(stderr, usage, argv[0]); + freecerr(); exit(1); } /* WORD値に変換 */ word = nh2word(argv[optind]); if(cerr->num > 0) { fprintf(stderr, "Dumpword Error - %d: %s\n", cerr->num, cerr->msg); + freecerr(); exit(1); } fprintf(stdout, "%6s: ", argv[optind]); print_dumpword(word, logicalmode); fprintf(stdout, "\n"); + freecerr(); return 0; }