@@ -77,10 +77,12 @@ static void stdio_restore_cleanup(void)
7777
7878 if (env .subtest_state ) {
7979 fclose (env .subtest_state -> stdout );
80+ env .subtest_state -> stdout = NULL ;
8081 stdout = env .test_state -> stdout ;
8182 stderr = env .test_state -> stdout ;
8283 } else {
8384 fclose (env .test_state -> stdout );
85+ env .test_state -> stdout = NULL ;
8486 }
8587#endif
8688}
@@ -1077,6 +1079,7 @@ static int read_prog_test_msg(int sock_fd, struct msg *msg, enum msg_type type)
10771079static int dispatch_thread_read_log (int sock_fd , char * * log_buf , size_t * log_cnt )
10781080{
10791081 FILE * log_fp = NULL ;
1082+ int result = 0 ;
10801083
10811084 log_fp = open_memstream (log_buf , log_cnt );
10821085 if (!log_fp )
@@ -1085,16 +1088,20 @@ static int dispatch_thread_read_log(int sock_fd, char **log_buf, size_t *log_cnt
10851088 while (true) {
10861089 struct msg msg ;
10871090
1088- if (read_prog_test_msg (sock_fd , & msg , MSG_TEST_LOG ))
1089- return 1 ;
1091+ if (read_prog_test_msg (sock_fd , & msg , MSG_TEST_LOG )) {
1092+ result = 1 ;
1093+ goto out ;
1094+ }
10901095
10911096 fprintf (log_fp , "%s" , msg .test_log .log_buf );
10921097 if (msg .test_log .is_last )
10931098 break ;
10941099 }
1100+
1101+ out :
10951102 fclose (log_fp );
10961103 log_fp = NULL ;
1097- return 0 ;
1104+ return result ;
10981105}
10991106
11001107static int dispatch_thread_send_subtests (int sock_fd , struct test_state * state )
@@ -1132,7 +1139,6 @@ static void *dispatch_thread(void *ctx)
11321139{
11331140 struct dispatch_data * data = ctx ;
11341141 int sock_fd ;
1135- FILE * log_fp = NULL ;
11361142
11371143 sock_fd = data -> sock_fd ;
11381144
@@ -1214,8 +1220,6 @@ static void *dispatch_thread(void *ctx)
12141220 if (env .debug )
12151221 fprintf (stderr , "[%d]: Protocol/IO error: %s.\n" , data -> worker_id , strerror (errno ));
12161222
1217- if (log_fp )
1218- fclose (log_fp );
12191223done :
12201224 {
12211225 struct msg msg_exit ;
@@ -1685,6 +1689,7 @@ int main(int argc, char **argv)
16851689 unload_bpf_testmod ();
16861690
16871691 free_test_selector (& env .test_selector );
1692+ free_test_selector (& env .subtest_selector );
16881693 free_test_states ();
16891694
16901695 if (env .succ_cnt + env .fail_cnt + env .skip_cnt == 0 )
0 commit comments