Browse Source

fix: 修复了if branch的else分支无返回result的问题

if branch执行else之后默认释放了result
导致出现了错误
SongZihuan 4 năm trước cách đây
mục cha
commit
5b5db4cae9
2 tập tin đã thay đổi với 9 bổ sung6 xóa
  1. 3 0
      vmcore/src/run.c
  2. 6 6
      vmcore/src/runbranch.c

+ 3 - 0
vmcore/src/run.c

@@ -48,6 +48,9 @@ ResultType runStatement(FUNC) {
             break;
         case if_branch:
             type = ifBranch(CNEXT);
+            if (result->value == NULL) {
+                printf("It is NULL\n");
+            }
             break;
         case while_branch:
             type = whileBranch(CNEXT);

+ 6 - 6
vmcore/src/runbranch.c

@@ -192,8 +192,8 @@ ResultType ifBranch(FUNC) {
         if (ifBranchSafeInterStatement(CFUNC(else_st, var_list, result, belong))) {
             set_result = false;
             result_from = info_else_branch;
-        }
-        freeResult(result);
+        } else
+            freeResult(result);
     }
 
     if (finally != NULL && !runFinally(set_result, ifBranchSafeInterStatement, finally, CNEXT_NT)) {
@@ -867,9 +867,9 @@ ResultType tryBranch(FUNC) {
                     result_from = info_vl_branch;
                     except_list = NULL;
                     else_st = NULL;
-                }
+                } else
+                    freeResult(result);
                 gc_freeTmpLink(&error_value->gc_status);
-                freeResult(result);
             }
         } else
             freeResult(result);
@@ -884,8 +884,8 @@ ResultType tryBranch(FUNC) {
             if (!CHECK_RESULT(result)) {
                 set_result = false;
                 else_st = NULL;
-            }
-            freeResult(result);
+            } else
+                freeResult(result);
         }
         info_vl = except_list->code;
     }