Skip to content

Commit 10fb949

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

File tree

2 files changed

+41
-7
lines changed

2 files changed

+41
-7
lines changed

menu/main.cpp

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -410,7 +410,9 @@ uint32 S9xReadJoypad (int which1)
410410
fp = popen(shell_cmd, "r");
411411
if (fp == NULL) {
412412
printf("Failed to run command %s\n", shell_cmd);
413-
}
413+
} else {
414+
pclose(fp);
415+
}
414416

415417
// Save config file
416418
configfile_save(cfg_file_rom);
@@ -599,16 +601,21 @@ void S9xLoadSRAM (void)
599601
/* Quick save and turn off the console */
600602
void quick_save_and_poweroff()
601603
{
604+
FILE * fp;
605+
602606
printf("Save Instant Play file\n");
603607

604608
/* Send command to cancel any previously scheduled powerdown */
605-
if (popen(SHELL_CMD_CANCEL_SCHED_POWERDOWN, "r") == NULL)
609+
fp = popen(SHELL_CMD_CANCEL_SCHED_POWERDOWN, "r");
610+
if (fp == NULL)
606611
{
607612
/* Countdown is still ticking, so better do nothing
608613
than start writing and get interrupted!
609614
*/
610615
printf("Failed to cancel scheduled shutdown\n");
611616
exit(0);
617+
} else {
618+
pclose(fp);
612619
}
613620

614621
/* Save */

menu/menu.cpp

Lines changed: 32 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -397,6 +397,7 @@ void init_menu_system_values(){
397397
volume_percentage = 50; ///wrong value: setting default to 50
398398
}
399399
else{
400+
pclose(fp);
400401
fgets(res, sizeof(res)-1, fp);
401402

402403
/// Check if Volume is a number (at least the first char)
@@ -417,6 +418,7 @@ void init_menu_system_values(){
417418
brightness_percentage = 50; ///wrong value: setting default to 50
418419
}
419420
else{
421+
pclose(fp);
420422
fgets(res, sizeof(res)-1, fp);
421423

422424
/// Check if brightness is a number (at least the first char)
@@ -659,7 +661,10 @@ void run_menu_loop()
659661
RES_HW_SCREEN_HORIZONTAL * RES_HW_SCREEN_VERTICAL * sizeof(u16));
660662

661663
/* Stop Ampli */
662-
popen(SHELL_CMD_TURN_AMPLI_OFF, "r");
664+
fp = popen(SHELL_CMD_TURN_AMPLI_OFF, "r");
665+
if (fp != NULL) {
666+
pclose(fp);
667+
}
663668

664669
/// -------- Main loop ---------
665670
while (!stop_menu_loop)
@@ -737,7 +742,9 @@ void run_menu_loop()
737742
fp = popen(shell_cmd, "r");
738743
if (fp == NULL) {
739744
MENU_ERROR_PRINTF("Failed to run command %s\n", shell_cmd);
740-
}
745+
} else {
746+
pclose(fp);
747+
}
741748

742749
/// ------ Refresh screen ------
743750
screen_refresh = 1;
@@ -753,6 +760,8 @@ void run_menu_loop()
753760
fp = popen(shell_cmd, "r");
754761
if (fp == NULL) {
755762
MENU_ERROR_PRINTF("Failed to run command %s\n", shell_cmd);
763+
} else {
764+
pclose(fp);
756765
}
757766
/// ------ Refresh screen ------
758767
screen_refresh = 1;
@@ -809,6 +818,8 @@ void run_menu_loop()
809818
fp = popen(shell_cmd, "r");
810819
if (fp == NULL) {
811820
MENU_ERROR_PRINTF("Failed to run command %s\n", shell_cmd);
821+
} else {
822+
pclose(fp);
812823
}
813824
/// ------ Refresh screen ------
814825
screen_refresh = 1;
@@ -824,6 +835,8 @@ void run_menu_loop()
824835
fp = popen(shell_cmd, "r");
825836
if (fp == NULL) {
826837
MENU_ERROR_PRINTF("Failed to run command %s\n", shell_cmd);
838+
} else {
839+
pclose(fp);
827840
}
828841
/// ------ Refresh screen ------
829842
screen_refresh = 1;
@@ -885,6 +898,8 @@ void run_menu_loop()
885898
fp = popen(shell_cmd, "r");
886899
if (fp == NULL) {
887900
MENU_ERROR_PRINTF("Failed to run command %s\n", shell_cmd);
901+
} else {
902+
pclose(fp);
888903
}
889904

890905
stop_menu_loop = 1;
@@ -922,6 +937,8 @@ void run_menu_loop()
922937
fp = popen(shell_cmd, "r");
923938
if (fp == NULL) {
924939
MENU_ERROR_PRINTF("Failed to run command %s\n", shell_cmd);
940+
} else {
941+
pclose(fp);
925942
}
926943

927944
stop_menu_loop = 1;
@@ -1019,7 +1036,10 @@ void run_menu_loop()
10191036
}
10201037

10211038
/* Start Ampli */
1022-
popen(SHELL_CMD_TURN_AMPLI_ON, "r");
1039+
fp = popen(SHELL_CMD_TURN_AMPLI_ON, "r");
1040+
if (fp != NULL) {
1041+
pclose(fp);
1042+
}
10231043
}
10241044

10251045

@@ -1042,9 +1062,13 @@ int launch_resume_menu_loop()
10421062
uint8_t screen_refresh = 1;
10431063
uint8_t menu_confirmation = 0;
10441064
int option_idx=RESUME_YES;
1065+
FILE *fp;
10451066

10461067
/* Stop Ampli */
1047-
popen(SHELL_CMD_TURN_AMPLI_OFF, "r");
1068+
fp = popen(SHELL_CMD_TURN_AMPLI_OFF, "r");
1069+
if (fp != NULL) {
1070+
pclose(fp);
1071+
}
10481072

10491073
/* Save prev key repeat params and set new Key repeat */
10501074
SDL_GetKeyRepeat(&backup_key_repeat_delay, &backup_key_repeat_interval);
@@ -1209,7 +1233,10 @@ int launch_resume_menu_loop()
12091233
}
12101234

12111235
/* Start Ampli */
1212-
popen(SHELL_CMD_TURN_AMPLI_ON, "r");
1236+
fp = popen(SHELL_CMD_TURN_AMPLI_ON, "r");
1237+
if (fp != NULL) {
1238+
pclose(fp);
1239+
}
12131240

12141241
return option_idx;
12151242
}

0 commit comments

Comments
 (0)