Skip to content

Commit 643b9eb

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

File tree

3 files changed

+68
-16
lines changed

3 files changed

+68
-16
lines changed

input.c

Lines changed: 27 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -829,7 +829,9 @@ u32 update_input()
829829
fp = popen(shell_cmd, "r");
830830
if (fp == NULL) {
831831
printf("Failed to run command %s\n", shell_cmd);
832-
}
832+
} else {
833+
pclose(fp);
834+
}
833835
}
834836
/// --- Quick load ---
835837
else if(event.key.keysym.sym == SDLK_F7)
@@ -849,7 +851,9 @@ u32 update_input()
849851
fp = popen(shell_cmd, "r");
850852
if (fp == NULL) {
851853
printf("Failed to run command %s\n", shell_cmd);
852-
}
854+
} else {
855+
pclose(fp);
856+
}
853857
return 1;
854858
}
855859
/// --- Volume Up ---
@@ -864,7 +868,9 @@ u32 update_input()
864868
fp = popen(shell_cmd, "r");
865869
if (fp == NULL) {
866870
printf("Failed to run command %s\n", shell_cmd);
867-
}
871+
} else {
872+
pclose(fp);
873+
}
868874

869875
/// ----- Hud Msg -----
870876
sprintf(hud_msg, "VOLUME %d%%", volume_percentage);
@@ -882,7 +888,9 @@ u32 update_input()
882888
fp = popen(shell_cmd, "r");
883889
if (fp == NULL) {
884890
printf("Failed to run command %s\n", shell_cmd);
885-
}
891+
} else {
892+
pclose(fp);
893+
}
886894

887895
/// ----- Hud Msg -----
888896
sprintf(hud_msg, "VOLUME %d%%", volume_percentage);
@@ -900,7 +908,9 @@ u32 update_input()
900908
fp = popen(shell_cmd, "r");
901909
if (fp == NULL) {
902910
printf("Failed to run command %s\n", shell_cmd);
903-
}
911+
} else {
912+
pclose(fp);
913+
}
904914

905915
/// ----- Hud Msg -----
906916
sprintf(hud_msg, "BRIGHTNESS %d%%", brightness_percentage);
@@ -918,7 +928,9 @@ u32 update_input()
918928
fp = popen(shell_cmd, "r");
919929
if (fp == NULL) {
920930
printf("Failed to run command %s\n", shell_cmd);
921-
}
931+
} else {
932+
pclose(fp);
933+
}
922934

923935
/// ----- Hud Msg -----
924936
sprintf(hud_msg, "BRIGHTNESS %d%%", brightness_percentage);
@@ -943,7 +955,9 @@ u32 update_input()
943955
fp = popen(shell_cmd, "r");
944956
if (fp == NULL) {
945957
printf("Failed to run command %s\n", shell_cmd);
946-
}
958+
} else {
959+
pclose(fp);
960+
}
947961

948962
// Save config file
949963
configfile_save(cfg_file_rom);
@@ -967,7 +981,9 @@ u32 update_input()
967981
fp = popen(shell_cmd, "r");
968982
if (fp == NULL) {
969983
printf("Failed to run command %s\n", shell_cmd);
970-
}
984+
} else {
985+
pclose(fp);
986+
}
971987

972988
// Save config file
973989
configfile_save(cfg_file_rom);
@@ -993,7 +1009,9 @@ u32 update_input()
9931009
fp = popen(shell_cmd, "r");
9941010
if (fp == NULL) {
9951011
printf("Failed to run command %s\n", shell_cmd);
996-
}
1012+
} else {
1013+
pclose(fp);
1014+
}
9971015

9981016
// Save config file
9991017
configfile_save(cfg_file_rom);

main.c

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -250,17 +250,21 @@ void init_main()
250250
/* Quick save and turn off the console */
251251
void quick_save_and_poweroff()
252252
{
253+
FILE *fp;
254+
253255
printf("Save Instant Play file\n");
254256

255257
/* Send command to cancel any previously scheduled powerdown */
256-
if (popen(SHELL_CMD_CANCEL_SCHED_POWERDOWN, "r") == NULL)
258+
fp = popen(SHELL_CMD_CANCEL_SCHED_POWERDOWN, "r");
259+
if (fp == NULL)
257260
{
258261
/* Countdown is still ticking, so better do nothing
259262
than start writing and get interrupted!
260263
*/
261264
printf("Failed to cancel scheduled shutdown\n");
262265
exit(0);
263266
}
267+
pclose(fp);
264268

265269
/* Save */
266270
u16 *current_screen = copy_screen();
@@ -464,6 +468,8 @@ int main(int argc, char *argv[])
464468
FILE *fp = popen(shell_cmd, "r");
465469
if (fp == NULL) {
466470
printf("In %s, Failed to run command %s\n", __func__, shell_cmd);
471+
} else {
472+
pclose(fp);
467473
}
468474

469475
while(gui_action == CURSOR_NONE)
@@ -476,9 +482,10 @@ int main(int argc, char *argv[])
476482
fp = popen(SHELL_CMD_NOTIF_CLEAR, "r");
477483
if (fp == NULL) {
478484
printf("In %s, Failed to run command %s\n", __func__, SHELL_CMD_NOTIF_CLEAR);
485+
} else {
486+
pclose(fp);
479487
}
480488

481-
482489
debug_screen_end();
483490

484491
quit();

menu.c

Lines changed: 32 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -368,6 +368,7 @@ void init_menu_system_values(){
368368
volume_percentage = 50; ///wrong value: setting default to 50
369369
}
370370
else{
371+
pclose(fp);
371372
fgets(res, sizeof(res)-1, fp);
372373

373374
/// Check if Volume is a number (at least the first char)
@@ -388,6 +389,7 @@ void init_menu_system_values(){
388389
brightness_percentage = 50; ///wrong value: setting default to 50
389390
}
390391
else{
392+
pclose(fp);
391393
fgets(res, sizeof(res)-1, fp);
392394

393395
/// Check if brightness is a number (at least the first char)
@@ -633,7 +635,10 @@ void run_menu_loop()
633635
RES_HW_SCREEN_HORIZONTAL * RES_HW_SCREEN_VERTICAL * sizeof(u16));
634636

635637
/* Stop Ampli */
636-
popen(SHELL_CMD_TURN_AMPLI_OFF, "r");
638+
fp = popen(SHELL_CMD_TURN_AMPLI_OFF, "r");
639+
if (fp != NULL) {
640+
pclose(fp);
641+
}
637642

638643
/// -------- Main loop ---------
639644
while (!stop_menu_loop)
@@ -713,7 +718,9 @@ void run_menu_loop()
713718
fp = popen(shell_cmd, "r");
714719
if (fp == NULL) {
715720
MENU_ERROR_PRINTF("Failed to run command %s\n", shell_cmd);
716-
}
721+
} else {
722+
pclose(fp);
723+
}
717724

718725
/// ------ Refresh screen ------
719726
screen_refresh = 1;
@@ -729,6 +736,8 @@ void run_menu_loop()
729736
fp = popen(shell_cmd, "r");
730737
if (fp == NULL) {
731738
MENU_ERROR_PRINTF("Failed to run command %s\n", shell_cmd);
739+
} else {
740+
pclose(fp);
732741
}
733742
/// ------ Refresh screen ------
734743
screen_refresh = 1;
@@ -785,6 +794,8 @@ void run_menu_loop()
785794
fp = popen(shell_cmd, "r");
786795
if (fp == NULL) {
787796
MENU_ERROR_PRINTF("Failed to run command %s\n", shell_cmd);
797+
} else {
798+
pclose(fp);
788799
}
789800
/// ------ Refresh screen ------
790801
screen_refresh = 1;
@@ -800,6 +811,8 @@ void run_menu_loop()
800811
fp = popen(shell_cmd, "r");
801812
if (fp == NULL) {
802813
MENU_ERROR_PRINTF("Failed to run command %s\n", shell_cmd);
814+
} else {
815+
pclose(fp);
803816
}
804817
/// ------ Refresh screen ------
805818
screen_refresh = 1;
@@ -861,6 +874,8 @@ void run_menu_loop()
861874
fp = popen(shell_cmd, "r");
862875
if (fp == NULL) {
863876
MENU_ERROR_PRINTF("Failed to run command %s\n", shell_cmd);
877+
} else {
878+
pclose(fp);
864879
}
865880

866881
stop_menu_loop = 1;
@@ -899,6 +914,8 @@ void run_menu_loop()
899914
fp = popen(shell_cmd, "r");
900915
if (fp == NULL) {
901916
MENU_ERROR_PRINTF("Failed to run command %s\n", shell_cmd);
917+
} else {
918+
pclose(fp);
902919
}
903920

904921
stop_menu_loop = 1;
@@ -995,7 +1012,10 @@ void run_menu_loop()
9951012
}
9961013

9971014
/* Start Ampli */
998-
popen(SHELL_CMD_TURN_AMPLI_ON, "r");
1015+
fp = popen(SHELL_CMD_TURN_AMPLI_ON, "r");
1016+
if (fp != NULL) {
1017+
pclose(fp);
1018+
}
9991019

10001020
/// ------ Reset last screen ------
10011021
SDL_BlitSurface(backup_hw_screen, NULL, hw_screen, NULL);
@@ -1022,9 +1042,13 @@ int launch_resume_menu_loop()
10221042
uint8_t screen_refresh = 1;
10231043
uint8_t menu_confirmation = 0;
10241044
int option_idx=RESUME_YES;
1045+
FILE *fp;
10251046

10261047
/* Stop Ampli */
1027-
popen(SHELL_CMD_TURN_AMPLI_OFF, "r");
1048+
fp = popen(SHELL_CMD_TURN_AMPLI_OFF, "r");
1049+
if (fp != NULL) {
1050+
pclose(fp);
1051+
}
10281052

10291053
/* Save prev key repeat params and set new Key repeat */
10301054
SDL_GetKeyRepeat(&backup_key_repeat_delay, &backup_key_repeat_interval);
@@ -1193,7 +1217,10 @@ int launch_resume_menu_loop()
11931217
}
11941218

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

11981225
return option_idx;
11991226
}

0 commit comments

Comments
 (0)