Skip to content

Commit d721539

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

File tree

3 files changed

+39
-7
lines changed

3 files changed

+39
-7
lines changed

src/drivers/dingux-sdl/dingoo.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -298,17 +298,20 @@ void handle_sigusr1(int sig)
298298
/* Quick save and turn off the console */
299299
void quick_save_and_poweroff()
300300
{
301+
FILE *fp;
301302
printf("Save Instant Play file\n");
302303

303304
/* Send command to cancel any previously scheduled powerdown */
304-
if (popen(SHELL_CMD_CANCEL_SCHED_POWERDOWN, "r") == NULL)
305+
fp = popen(SHELL_CMD_CANCEL_SCHED_POWERDOWN, "r");
306+
if (fp == NULL)
305307
{
306308
/* Countdown is still ticking, so better do nothing
307309
than start writing and get interrupted!
308310
*/
309311
printf("Failed to cancel scheduled shutdown\n");
310312
exit(0);
311313
}
314+
pclose(fp);
312315

313316
/* Save */
314317
FCEUI_SaveState(quick_save_file);

src/drivers/dingux-sdl/input.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -332,6 +332,8 @@ static void KeyboardCommands() {
332332
fp_tmp = popen(shell_cmd_tmp, "r");
333333
if (fp_tmp == NULL) {
334334
printf("Failed to run command %s\n", shell_cmd_tmp);
335+
} else {
336+
pclose(fp_tmp);
335337
}
336338

337339
// Save config file

src/drivers/dingux-sdl/menu.cpp

Lines changed: 33 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -377,6 +377,7 @@ void init_menu_system_values(){
377377
volume_percentage = 50; ///wrong value: setting default to 50
378378
}
379379
else{
380+
pclose(fp);
380381
fgets(res, sizeof(res)-1, fp);
381382

382383
/// Check if Volume is a number (at least the first char)
@@ -397,6 +398,7 @@ void init_menu_system_values(){
397398
brightness_percentage = 50; ///wrong value: setting default to 50
398399
}
399400
else{
401+
pclose(fp);
400402
fgets(res, sizeof(res)-1, fp);
401403

402404
/// Check if brightness is a number (at least the first char)
@@ -640,7 +642,10 @@ void run_menu_loop()
640642
RES_HW_SCREEN_HORIZONTAL * RES_HW_SCREEN_VERTICAL * sizeof(u16));
641643

642644
/* Stop Ampli */
643-
popen(SHELL_CMD_TURN_AMPLI_OFF, "r");
645+
fp = popen(SHELL_CMD_TURN_AMPLI_OFF, "r");
646+
if (fp != NULL) {
647+
pclose(fp);
648+
}
644649

645650
/// -------- Main loop ---------
646651
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,6 +799,8 @@ 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);
802+
} else {
803+
pclose(fp);
793804
}
794805
/// ------ Refresh screen ------
795806
screen_refresh = 1;
@@ -805,6 +816,8 @@ void run_menu_loop()
805816
fp = popen(shell_cmd, "r");
806817
if (fp == NULL) {
807818
MENU_ERROR_PRINTF("Failed to run command %s\n", shell_cmd);
819+
} else {
820+
pclose(fp);
808821
}
809822
/// ------ Refresh screen ------
810823
screen_refresh = 1;
@@ -865,6 +878,8 @@ void run_menu_loop()
865878
fp = popen(shell_cmd, "r");
866879
if (fp == NULL) {
867880
MENU_ERROR_PRINTF("Failed to run command %s\n", shell_cmd);
881+
} else {
882+
pclose(fp);
868883
}
869884

870885
stop_menu_loop = 1;
@@ -903,6 +918,8 @@ void run_menu_loop()
903918
fp = popen(shell_cmd, "r");
904919
if (fp == NULL) {
905920
MENU_ERROR_PRINTF("Failed to run command %s\n", shell_cmd);
921+
} else {
922+
pclose(fp);
906923
}
907924

908925
stop_menu_loop = 1;
@@ -998,7 +1015,10 @@ void run_menu_loop()
9981015
}
9991016

10001017
/* Start Ampli */
1001-
popen(SHELL_CMD_TURN_AMPLI_ON, "r");
1018+
fp = popen(SHELL_CMD_TURN_AMPLI_ON, "r");
1019+
if (fp != NULL) {
1020+
pclose(fp);
1021+
}
10021022
}
10031023

10041024

@@ -1020,10 +1040,14 @@ int launch_resume_menu_loop()
10201040
stop_menu_loop = 0;
10211041
uint8_t screen_refresh = 1;
10221042
uint8_t menu_confirmation = 0;
1023-
int option_idx=RESUME_YES;
1043+
int option_idx=RESUME_YES;
1044+
FILE *fp;
10241045

10251046
/* Stop Ampli */
1026-
popen(SHELL_CMD_TURN_AMPLI_OFF, "r");
1047+
fp = popen(SHELL_CMD_TURN_AMPLI_OFF, "r");
1048+
if (fp != NULL) {
1049+
pclose(fp);
1050+
}
10271051

10281052
/* Save prev key repeat params and set new Key repeat */
10291053
SDL_GetKeyRepeat(&backup_key_repeat_delay, &backup_key_repeat_interval);
@@ -1188,7 +1212,10 @@ int launch_resume_menu_loop()
11881212
}
11891213

11901214
/* Start Ampli */
1191-
popen(SHELL_CMD_TURN_AMPLI_ON, "r");
1215+
fp = popen(SHELL_CMD_TURN_AMPLI_ON, "r");
1216+
if (fp != NULL) {
1217+
pclose(fp);
1218+
}
11921219

11931220
return option_idx;
11941221
}

0 commit comments

Comments
 (0)