Valgrindで見つかったメモリー周辺の問題点を修正
[YACASL2.git] / src / casl2.c
index 14f372c..c272d05 100644 (file)
@@ -37,6 +37,14 @@ CERR cerr_casl2[] = {
     { 126, "no source file" },
 };
 
+/**
+ * CASL IIのエラーをエラーリストに追加
+ */
+void addcerrlist_casl2()
+{
+    addcerrlist(ARRAYSIZE(cerr_casl2), cerr_casl2);
+}
+
 /**
  * アセンブル結果を書き込むファイルの名前
  */
@@ -61,7 +69,7 @@ int main(int argc, char *argv[])
         "Usage: %s [-slLaAtTdh] [-oO[<OBJECTFILE>]] [-M <MEMORYSIZE>] [-C <CLOCKS>] FILE1[ FILE2  ...]\n";
 
     cerr_init();
-    addcerrlist(ARRAYSIZE(cerr_casl2), cerr_casl2);
+    addcerrlist_casl2();
     addcerrlist_assemble();
     addcerrlist_exec();
     /* オプションの処理 */
@@ -127,7 +135,7 @@ int main(int argc, char *argv[])
     for(pass = FIRST; pass <= SECOND; pass++) {
         if(pass == FIRST) {
             create_cmdtype_code();        /* 命令の名前とタイプがキーのハッシュ表を作成 */
-            asptr = malloc_chk(sizeof(asptr), "asptr"); /* アセンブル時のプロパティ用の領域確保 */
+            asptr = malloc_chk(sizeof(ASPTR), "asptr"); /* アセンブル時のプロパティ用の領域確保 */
         }
         for(i = optind; i < argc; i++) {
             /* データの格納開始位置 */
@@ -136,7 +144,6 @@ int main(int argc, char *argv[])
             } else if(pass == SECOND) {
                 asptr->ptr = beginptr[i];
             }
-            asptr->prog = NULL;
             if(execmode.trace == true || execmode.dump == true || asmode.src == true ||
                asmode.label == true || asmode.asdetail == true)
             {
@@ -156,15 +163,14 @@ int main(int argc, char *argv[])
         }
         if(pass == SECOND) {
             freelabel();            /* ラベルハッシュ表を解放 */
-            free_chk(asptr->prog, "asptr.prog"); /* プログラム名を解放 */
-            free_chk(asptr, "asptr");       /* アセンブル時のプロパティを解放 */
             free_cmdtype_code();    /* 命令の名前とタイプがキーのハッシュ表を解放 */
+            FREE(asptr);       /* アセンブル時のプロパティを解放 */
         }
     }
     if(res == true) {
         if(objfile != NULL) {
             outassemble(objfile);
-            free_chk(objfile, "objfile");
+            FREE(objfile);
         }
         if(asmode.onlyassemble == false) {
             create_code_type();    /* 命令のコードとタイプがキーのハッシュ表を作成 */