@@ -33,14 +33,19 @@ int mock_activation_sockets(void)
3333 unlink (addr .sun_path );
3434
3535 fd = socket (AF_UNIX , SOCK_STREAM , 0 );
36- if (fd == -1 ) return -1 ;
36+ if (fd == -1 ) {
37+ ret = -1 ;
38+ goto done ;
39+ }
3740
3841 ret = bind (fd , (struct sockaddr * )& addr , sizeof (addr ));
39- if (ret == -1 ) return -1 ;
42+ if (ret == -1 ) goto done ;
4043
4144 ret = listen (fd , 1 );
42- if (ret == -1 ) return -1 ;
45+ if (ret == -1 ) goto done ;
4346
47+ done :
48+ if (ret == -1 ) close (fd );
4449 return 0 ;
4550}
4651
@@ -75,19 +80,19 @@ int wait_and_check_output(int outfd, int timeout)
7580 useconds_t interval = 100 * 1000 ; /* 100 msec */
7681 char outbuf [1024 ];
7782 char * line ;
78- FILE * out ;
79- int ret ;
83+ FILE * out = NULL ;
84+ int err , ret = -1 ;
8085
8186 /* make pipe non blocking */
82- ret = fcntl (outfd , F_SETFL , O_NONBLOCK );
83- if (ret ) return -1 ;
87+ err = fcntl (outfd , F_SETFL , O_NONBLOCK );
88+ if (err ) goto done ;
8489
8590 out = fdopen (outfd , "r" );
86- if (!out ) return -1 ;
91+ if (!out ) goto done ;
8792
8893 while (now < start + timeout ) {
89- ret = usleep (interval );
90- if (ret ) return -1 ;
94+ err = usleep (interval );
95+ if (err ) goto done ;
9196
9297 line = fgets (outbuf , 1023 , out );
9398 if (line ) {
@@ -101,13 +106,15 @@ int wait_and_check_output(int outfd, int timeout)
101106 now = time (NULL );
102107 }
103108
104- fclose (out );
105-
106109 for (int i = 0 ; checks [i ].match != NULL ; i ++ ) {
107- if (checks [i ].matched == false) return -1 ;
110+ if (checks [i ].matched == false) goto done ;
108111 }
109112
110- return 0 ;
113+ ret = 0 ;
114+
115+ done :
116+ if (out ) fclose (out );
117+ return ret ;
111118}
112119
113120int child (int outpipe [])
0 commit comments