Skip to content

Commit ba18334

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

File tree

3 files changed

+44
-6
lines changed

3 files changed

+44
-6
lines changed

src/drivers/input.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -860,8 +860,11 @@ void Input_Event(const SDL_Event *event)
860860
FILE *fp = popen(shell_cmd, "r");
861861
if (fp == NULL) {
862862
printf("Failed to run command %s\n", shell_cmd);
863+
} else {
864+
pclose(fp);
863865
}
864866

867+
865868
// Save config file
866869
configfile_save(cfg_file_rom);
867870
break;
@@ -882,6 +885,8 @@ void Input_Event(const SDL_Event *event)
882885
FILE *fp = popen(shell_cmd, "r");
883886
if (fp == NULL) {
884887
printf("Failed to run command %s\n", shell_cmd);
888+
} else {
889+
pclose(fp);
885890
}
886891

887892
// Save config file
@@ -905,6 +910,8 @@ void Input_Event(const SDL_Event *event)
905910
FILE *fp = popen(shell_cmd, "r");
906911
if (fp == NULL) {
907912
printf("Failed to run command %s\n", shell_cmd);
913+
} else {
914+
pclose(fp);
908915
}
909916

910917
// Save config file

src/drivers/main.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1282,17 +1282,21 @@ static volatile int gte_write = 0;
12821282
/* Quick save and turn off the console */
12831283
void quick_save_and_poweroff()
12841284
{
1285+
FILE *fp;
1286+
12851287
printf("Save Instant Play file\n");
12861288

12871289
/* Send command to cancel any previously scheduled powerdown */
1288-
if (popen(SHELL_CMD_CANCEL_SCHED_POWERDOWN, "r") == NULL)
1290+
fp = popen(SHELL_CMD_CANCEL_SCHED_POWERDOWN, "r");
1291+
if (fp == NULL)
12891292
{
12901293
/* Countdown is still ticking, so better do nothing
12911294
than start writing and get interrupted!
12921295
*/
12931296
printf("Failed to cancel scheduled shutdown\n");
12941297
exit(0);
12951298
}
1299+
pclose(fp);
12961300

12971301
/* Quick Save */
12981302
MDFNI_SaveState(quick_save_file, NULL, NULL, NULL, NULL);

src/drivers/menu.cpp

Lines changed: 32 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -431,6 +431,7 @@ void init_menu_system_values(){
431431
volume_percentage = 50; ///wrong value: setting default to 50
432432
}
433433
else{
434+
pclose(fp);
434435
fgets(res, sizeof(res)-1, fp);
435436

436437
/// Check if Volume is a number (at least the first char)
@@ -451,6 +452,7 @@ void init_menu_system_values(){
451452
brightness_percentage = 50; ///wrong value: setting default to 50
452453
}
453454
else{
455+
pclose(fp);
454456
fgets(res, sizeof(res)-1, fp);
455457

456458
/// Check if brightness is a number (at least the first char)
@@ -702,7 +704,10 @@ void run_menu_loop()
702704
RES_HW_SCREEN_HORIZONTAL * RES_HW_SCREEN_VERTICAL * sizeof(uint16_t));*/
703705

704706
/* Stop Ampli */
705-
popen(SHELL_CMD_TURN_AMPLI_OFF, "r");
707+
fp = popen(SHELL_CMD_TURN_AMPLI_OFF, "r");
708+
if (fp != NULL) {
709+
pclose(fp);
710+
}
706711

707712
/// -------- Main loop ---------
708713
while (!stop_menu_loop)
@@ -780,7 +785,9 @@ void run_menu_loop()
780785
fp = popen(shell_cmd, "r");
781786
if (fp == NULL) {
782787
MENU_ERROR_PRINTF("Failed to run command %s\n", shell_cmd);
783-
}
788+
} else {
789+
pclose(fp);
790+
}
784791

785792
/// ------ Refresh screen ------
786793
screen_refresh = 1;
@@ -796,6 +803,8 @@ void run_menu_loop()
796803
fp = popen(shell_cmd, "r");
797804
if (fp == NULL) {
798805
MENU_ERROR_PRINTF("Failed to run command %s\n", shell_cmd);
806+
} else {
807+
pclose(fp);
799808
}
800809
/// ------ Refresh screen ------
801810
screen_refresh = 1;
@@ -856,6 +865,8 @@ void run_menu_loop()
856865
fp = popen(shell_cmd, "r");
857866
if (fp == NULL) {
858867
MENU_ERROR_PRINTF("Failed to run command %s\n", shell_cmd);
868+
} else {
869+
pclose(fp);
859870
}
860871
/// ------ Refresh screen ------
861872
screen_refresh = 1;
@@ -871,6 +882,8 @@ void run_menu_loop()
871882
fp = popen(shell_cmd, "r");
872883
if (fp == NULL) {
873884
MENU_ERROR_PRINTF("Failed to run command %s\n", shell_cmd);
885+
} else {
886+
pclose(fp);
874887
}
875888
/// ------ Refresh screen ------
876889
screen_refresh = 1;
@@ -932,6 +945,8 @@ void run_menu_loop()
932945
fp = popen(shell_cmd, "r");
933946
if (fp == NULL) {
934947
MENU_ERROR_PRINTF("Failed to run command %s\n", shell_cmd);
948+
} else {
949+
pclose(fp);
935950
}
936951

937952
stop_menu_loop = 1;
@@ -969,6 +984,8 @@ void run_menu_loop()
969984
fp = popen(shell_cmd, "r");
970985
if (fp == NULL) {
971986
MENU_ERROR_PRINTF("Failed to run command %s\n", shell_cmd);
987+
} else {
988+
pclose(fp);
972989
}
973990

974991
stop_menu_loop = 1;
@@ -1069,7 +1086,10 @@ void run_menu_loop()
10691086
}
10701087

10711088
/* Start Ampli */
1072-
popen(SHELL_CMD_TURN_AMPLI_ON, "r");
1089+
fp = popen(SHELL_CMD_TURN_AMPLI_ON, "r");
1090+
if (fp != NULL) {
1091+
pclose(fp);
1092+
}
10731093

10741094
/// ------ Reset last screen ------
10751095
SDL_BlitSurface(backup_hw_screen, NULL, hw_screen, NULL);
@@ -1097,9 +1117,13 @@ int launch_resume_menu_loop()
10971117
uint8_t menu_confirmation = 0;
10981118
int option_idx=RESUME_YES;
10991119
pumpWrap_disabled = 1;
1120+
FILE *fp;
11001121

11011122
/* Stop Ampli */
1102-
popen(SHELL_CMD_TURN_AMPLI_OFF, "r");
1123+
fp = popen(SHELL_CMD_TURN_AMPLI_OFF, "r");
1124+
if (fp != NULL) {
1125+
pclose(fp);
1126+
}
11031127

11041128
/* Save prev key repeat params and set new Key repeat */
11051129
SDL_GetKeyRepeat(&backup_key_repeat_delay, &backup_key_repeat_interval);
@@ -1273,7 +1297,10 @@ int launch_resume_menu_loop()
12731297
pumpWrap_disabled = 0;
12741298

12751299
/* Start Ampli */
1276-
popen(SHELL_CMD_TURN_AMPLI_ON, "r");
1300+
fp = popen(SHELL_CMD_TURN_AMPLI_ON, "r");
1301+
if (fp != NULL) {
1302+
pclose(fp);
1303+
}
12771304

12781305
return option_idx;
12791306
}

0 commit comments

Comments
 (0)