2
0
Эх сурвалжийг харах

fix: 修复fopen后没fclose的bug

SongZihuan 3 жил өмнө
parent
commit
67e42d4e77

+ 3 - 2
src/core/bytecode.c

@@ -41,7 +41,7 @@ int writeByteCode(af_Code *code, FilePath path) {
     FILE *file = fopen(path, "wb");
     if (file == NULL) {
         re = 2;
-        goto RETURN_;
+        goto RETURN_2;
     }
 
     Done(byteWriteStr(file, HEAD));
@@ -54,8 +54,9 @@ int writeByteCode(af_Code *code, FilePath path) {
         goto RETURN_;
     }
 
-
 RETURN_:
+    fclose(file);
+RETURN_2:
     free(md5);
     return re;
 }

+ 1 - 1
src/help_info.c.in

@@ -1 +1 @@
-const char *help_info = "@help-info@";
+const char *const help_info = "@help-info@";

+ 2 - 1
src/main.c

@@ -40,7 +40,8 @@ static void printHelp(void);
 static int mainRun(ff_FFlags *ff);
 static int mainCL(ff_FFlags *ff);
 static int mainBuild(ff_FFlags *ff);
-extern const char *help_info;
+
+extern const char *const help_info;
 
 char *base_path = NULL;
 char *log_path = NULL;

+ 6 - 5
test/src/byte_code.c

@@ -16,14 +16,15 @@ int main() {
     af_Code *bt5 = makeBlockCode(parentheses, bt3, 0, 1, NULL, NULL);
     pushCode(&bt2, bt5);
 
-    if(writeByteCode(bt1, "test.aub") != 1) {
-        fprintf(stderr, "Write test.aub error.\n");
+    int re;
+    if((re = writeByteCode(bt1, "test.aub")) != 1) {
+        fprintf(stderr, "Write test.aub error[%d].\n", re);
         return EXIT_FAILURE;
     }
 
-    af_Code *get;
-    if(readByteCode(&get, "test.aub") != 1) {
-        fprintf(stderr, "Read test.aub error.\n");
+    af_Code *get = NULL;
+    if((re = readByteCode(&get, "test.aub")) != 1) {
+        fprintf(stderr, "Read test.aub error[%d] %s.\n", re);
         return EXIT_FAILURE;
     }