Skip to content

Commit a3309fa

Browse files
committed
add missing pclose()
Signed-off-by: Vincent-FK <[email protected]>
1 parent 6c00ea1 commit a3309fa

File tree

3 files changed

+49
-7
lines changed

3 files changed

+49
-7
lines changed

emu.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,19 +49,23 @@ rcvar_t emu_exports[] =
4949
/* Quick save and turn off the console */
5050
void quick_save_and_poweroff()
5151
{
52+
FILE *fp;
53+
5254
printf("Save Instant Play file\n");
5355

5456
Uint32 start = SDL_GetTicks();
5557

5658
/* Send command to cancel any previously scheduled powerdown */
57-
if (popen(SHELL_CMD_CANCEL_SCHED_POWERDOWN, "r") == NULL)
59+
fp = popen(SHELL_CMD_CANCEL_SCHED_POWERDOWN, "r");
60+
if (fp == NULL)
5861
{
5962
/* Countdown is still ticking, so better do nothing
6063
than start writing and get interrupted!
6164
*/
6265
printf("Failed to cancel scheduled shutdown\n");
6366
exit(0);
6467
}
68+
pclose(fp);
6569

6670
printf("============== Cancel time %d\n", SDL_GetTicks() - start);
6771
/* Save */

rccmds.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,8 @@ static int cmd_inc_volume(int argc, char **argv)
118118
if (fp == NULL)
119119
{
120120
printf("Failed to run command %s\n", shell_cmd);
121+
} else {
122+
pclose(fp);
121123
}
122124
return 0;
123125
}
@@ -138,6 +140,8 @@ static int cmd_dec_volume(int argc, char **argv)
138140
if (fp == NULL)
139141
{
140142
printf("Failed to run command %s\n", shell_cmd);
143+
} else {
144+
pclose(fp);
141145
}
142146
return 0;
143147
}
@@ -158,6 +162,8 @@ static int cmd_inc_brightness(int argc, char **argv)
158162
if (fp == NULL)
159163
{
160164
printf("Failed to run command %s\n", shell_cmd);
165+
} else {
166+
pclose(fp);
161167
}
162168
return 0;
163169
}
@@ -178,6 +184,8 @@ static int cmd_dec_brightness(int argc, char **argv)
178184
if (fp == NULL)
179185
{
180186
printf("Failed to run command %s\n", shell_cmd);
187+
} else {
188+
pclose(fp);
181189
}
182190
return 0;
183191
}
@@ -205,6 +213,8 @@ static int cmd_aspectratiochange(int argc, char **argv)
205213
if (fp == NULL)
206214
{
207215
printf("Failed to run command %s\n", shell_cmd);
216+
} else {
217+
pclose(fp);
208218
}
209219

210220
// Save config file

sys/sdl/sdl-menu.c

Lines changed: 34 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -380,6 +380,7 @@ void init_menu_system_values(){
380380
volume_percentage = 50; ///wrong value: setting default to 50
381381
}
382382
else{
383+
pclose(fp);
383384
fgets(res, sizeof(res)-1, fp);
384385

385386
/// Check if Volume is a number (at least the first char)
@@ -400,6 +401,7 @@ void init_menu_system_values(){
400401
brightness_percentage = 50; ///wrong value: setting default to 50
401402
}
402403
else{
404+
pclose(fp);
403405
fgets(res, sizeof(res)-1, fp);
404406

405407
/// Check if brightness is a number (at least the first char)
@@ -638,7 +640,10 @@ void run_menu_loop()
638640
}
639641

640642
/* Stop Ampli */
641-
popen(SHELL_CMD_TURN_AMPLI_OFF, "r");
643+
fp = popen(SHELL_CMD_TURN_AMPLI_OFF, "r");
644+
if (fp != NULL) {
645+
pclose(fp);
646+
}
642647

643648
/// -------- Main loop ---------
644649
while (!stop_menu_loop)
@@ -718,7 +723,9 @@ void run_menu_loop()
718723
fp = popen(shell_cmd, "r");
719724
if (fp == NULL) {
720725
MENU_ERROR_PRINTF("Failed to run command %s\n", shell_cmd);
721-
}
726+
} else {
727+
pclose(fp);
728+
}
722729

723730
/// ------ Refresh screen ------
724731
screen_refresh = 1;
@@ -734,6 +741,8 @@ void run_menu_loop()
734741
fp = popen(shell_cmd, "r");
735742
if (fp == NULL) {
736743
MENU_ERROR_PRINTF("Failed to run command %s\n", shell_cmd);
744+
} else {
745+
pclose(fp);
737746
}
738747
/// ------ Refresh screen ------
739748
screen_refresh = 1;
@@ -790,7 +799,10 @@ void run_menu_loop()
790799
fp = popen(shell_cmd, "r");
791800
if (fp == NULL) {
792801
MENU_ERROR_PRINTF("Failed to run command %s\n", shell_cmd);
793-
}
802+
} else {
803+
pclose(fp);
804+
}
805+
794806
/// ------ Refresh screen ------
795807
screen_refresh = 1;
796808
}
@@ -805,6 +817,8 @@ void run_menu_loop()
805817
fp = popen(shell_cmd, "r");
806818
if (fp == NULL) {
807819
MENU_ERROR_PRINTF("Failed to run command %s\n", shell_cmd);
820+
} else {
821+
pclose(fp);
808822
}
809823
/// ------ Refresh screen ------
810824
screen_refresh = 1;
@@ -863,6 +877,8 @@ void run_menu_loop()
863877
fp = popen(shell_cmd, "r");
864878
if (fp == NULL) {
865879
MENU_ERROR_PRINTF("Failed to run command %s\n", shell_cmd);
880+
} else {
881+
pclose(fp);
866882
}
867883

868884
stop_menu_loop = 1;
@@ -900,6 +916,8 @@ void run_menu_loop()
900916
fp = popen(shell_cmd, "r");
901917
if (fp == NULL) {
902918
MENU_ERROR_PRINTF("Failed to run command %s\n", shell_cmd);
919+
} else {
920+
pclose(fp);
903921
}
904922

905923
stop_menu_loop = 1;
@@ -995,7 +1013,10 @@ void run_menu_loop()
9951013
}
9961014

9971015
/* Start Ampli */
998-
popen(SHELL_CMD_TURN_AMPLI_ON, "r");
1016+
fp = popen(SHELL_CMD_TURN_AMPLI_ON, "r");
1017+
if (fp != NULL) {
1018+
pclose(fp);
1019+
}
9991020
}
10001021

10011022

@@ -1018,9 +1039,13 @@ int launch_resume_menu_loop()
10181039
uint8_t screen_refresh = 1;
10191040
uint8_t menu_confirmation = 0;
10201041
int option_idx=RESUME_YES;
1042+
FILE *fp;
10211043

10221044
/* Stop Ampli */
1023-
popen(SHELL_CMD_TURN_AMPLI_OFF, "r");
1045+
fp = popen(SHELL_CMD_TURN_AMPLI_OFF, "r");
1046+
if (fp != NULL) {
1047+
pclose(fp);
1048+
}
10241049

10251050
/* Save prev key repeat params and set new Key repeat */
10261051
SDL_GetKeyRepeat(&backup_key_repeat_delay, &backup_key_repeat_interval);
@@ -1193,7 +1218,10 @@ int launch_resume_menu_loop()
11931218
}
11941219

11951220
/* Start Ampli */
1196-
popen(SHELL_CMD_TURN_AMPLI_ON, "r");
1221+
fp = popen(SHELL_CMD_TURN_AMPLI_ON, "r");
1222+
if (fp != NULL) {
1223+
pclose(fp);
1224+
}
11971225

11981226
return option_idx;
11991227
}

0 commit comments

Comments
 (0)