1414
1515int tests_run = 0 ;
1616
17+ static void free_fans (t_fans * fans )
18+ {
19+ while (fans != NULL ) {
20+ t_fans * tmp = fans -> next ;
21+ free (fans -> fan_manual_path );
22+ free (fans -> fan_output_path );
23+ free (fans -> label );
24+ free (fans );
25+ fans = tmp ;
26+ }
27+ }
28+
29+ static void free_sensors (t_sensors * sensors )
30+ {
31+ while (sensors != NULL ) {
32+ t_sensors * tmp = sensors -> next ;
33+ free (sensors -> path );
34+ free (sensors );
35+ sensors = tmp ;
36+ }
37+ }
1738
1839static const char * test_sensor_paths ()
1940{
@@ -31,6 +52,7 @@ static const char *test_sensor_paths()
3152 tmp = tmp -> next ;
3253 }
3354
55+ free_sensors (sensors );
3456 return 0 ;
3557}
3658
@@ -51,6 +73,7 @@ static const char *test_fan_paths()
5173 }
5274
5375 mu_assert ("No fans found" , found_fan_path != 0 );
76+ free_fans (fans );
5477 return 0 ;
5578}
5679
@@ -95,6 +118,7 @@ static const char *test_get_temp()
95118 stress (2000 );
96119 unsigned short temp_2 = get_temp (sensors );
97120 mu_assert ("Invalid Higher temp test (if fan was already spinning high, this is not worrying)" , temp_1 < temp_2 );
121+ free_sensors (sensors );
98122 return 0 ;
99123}
100124
@@ -196,6 +220,9 @@ static const char *test_settings_reload()
196220 t_fans * fan = (t_fans * ) malloc ( sizeof ( t_fans ) );
197221 fan -> fan_id = 1 ;
198222 fan -> fan_min_speed = -1 ;
223+ fan -> fan_manual_path = NULL ;
224+ fan -> fan_output_path = NULL ;
225+ fan -> label = NULL ;
199226 fan -> next = NULL ;
200227
201228 signal (SIGHUP , handler );
@@ -207,7 +234,7 @@ static const char *test_settings_reload()
207234 mu_assert ("min_fan_speed value is not 6200 after SIGHUP" , fan -> fan_min_speed == 6200 );
208235 mu_assert ("polling_interval is not 2 after SIGHUP" , polling_interval == 2 );
209236 retrieve_settings ("./mbpfan.conf" , fan );
210- free (fan );
237+ free_fans (fan );
211238 return 0 ;
212239}
213240
0 commit comments