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

[HUST CSE] fix fgets_tc.c (#7503)

这个文件里存在使用fopen函数后没有关闭文件fclose的问题,而且stream=NULL时是不需要fclose的
chiehwarm 2 жил өмнө
parent
commit
b1415c4fc8

+ 7 - 1
examples/utest/testcases/posix/stdio_h/functions/fgets_tc.c

@@ -19,15 +19,21 @@ static int fgets_entry(void)
     fclose(stream);
 
     stream = fopen("fopen_file.txt","r");
+    if (stream == NULL)
+    {
+        perror("fopen fail");
+        ret = -1;
+        goto __exit;
+    }
     fgets(gets, sizeof(gets), stream);
 
     if(strcmp(gets, data))
     {
         ret = -1;
     }
+    fclose(stream);
 
 __exit:
-    fclose(stream);
     return ret;
 }