Skip to content

Commit 24d02b6

Browse files
committed
add missing pclose()
Signed-off-by: Vincent-FK <vincent.buso@funkey-project.com>
1 parent c2f5d2a commit 24d02b6

File tree

2 files changed

+59
-5
lines changed

2 files changed

+59
-5
lines changed

frontend/main.c

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,17 +74,20 @@ static char *cfg_file_extension = "fkcfg";
7474
/* Quick save and turn off the console */
7575
void quick_save_and_poweroff()
7676
{
77+
FILE *fp;
7778
printf("Save Instant Play file\n");
7879

7980
/* Send command to cancel any previously scheduled powerdown */
80-
if (popen(SHELL_CMD_CANCEL_SCHED_POWERDOWN, "r") == NULL)
81+
fp = popen(SHELL_CMD_CANCEL_SCHED_POWERDOWN, "r");
82+
if (fp == NULL)
8183
{
8284
/* Countdown is still ticking, so better do nothing
8385
than start writing and get interrupted!
8486
*/
8587
printf("Failed to cancel scheduled shutdown\n");
8688
exit(0);
8789
}
90+
pclose(fp);
8891

8992
/* Save */
9093
if(SaveState(quick_save_file)){
@@ -252,6 +255,8 @@ void do_emu_action(void)
252255
fp = popen(shell_cmd, "r");
253256
if (fp == NULL) {
254257
printf("Failed to run command %s\n", shell_cmd);
258+
} else {
259+
pclose(fp);
255260
}
256261
break;
257262
case SACTION_PRE_SAVE_STATE:
@@ -262,6 +267,8 @@ void do_emu_action(void)
262267
fp = popen(shell_cmd, "r");
263268
if (fp == NULL) {
264269
printf("Failed to run command %s\n", shell_cmd);
270+
} else {
271+
pclose(fp);
265272
}
266273

267274
emu_action_future = SACTION_SAVE_STATE;
@@ -275,6 +282,8 @@ void do_emu_action(void)
275282
fp = popen(shell_cmd, "r");
276283
if (fp == NULL) {
277284
printf("Failed to run command %s\n", shell_cmd);
285+
} else {
286+
pclose(fp);
278287
}
279288
break;
280289
#ifndef NO_FRONTEND
@@ -328,6 +337,8 @@ void do_emu_action(void)
328337
fp = popen(shell_cmd, "r");
329338
if (fp == NULL) {
330339
printf("Failed to run command %s\n", shell_cmd);
340+
} else {
341+
pclose(fp);
331342
}
332343

333344
// Save config file
@@ -349,6 +360,8 @@ void do_emu_action(void)
349360
fp = popen(shell_cmd, "r");
350361
if (fp == NULL) {
351362
printf("Failed to run command %s\n", shell_cmd);
363+
} else {
364+
pclose(fp);
352365
}
353366

354367
// Save config file
@@ -371,6 +384,8 @@ void do_emu_action(void)
371384
fp = popen(shell_cmd, "r");
372385
if (fp == NULL) {
373386
printf("Failed to run command %s\n", shell_cmd);
387+
} else {
388+
pclose(fp);
374389
}
375390

376391
// Save config file
@@ -429,6 +444,8 @@ void do_emu_action(void)
429444
fp = popen(shell_cmd, "r");
430445
if (fp == NULL) {
431446
printf("Failed to run command %s\n", shell_cmd);
447+
} else {
448+
pclose(fp);
432449
}
433450
break;
434451
case SACTION_VOLUME_UP:
@@ -442,6 +459,8 @@ void do_emu_action(void)
442459
fp = popen(shell_cmd, "r");
443460
if (fp == NULL) {
444461
printf("Failed to run command %s\n", shell_cmd);
462+
} else {
463+
pclose(fp);
445464
}
446465
break;
447466
case SACTION_BRIGHTNESS_DOWN:
@@ -455,6 +474,8 @@ void do_emu_action(void)
455474
fp = popen(shell_cmd, "r");
456475
if (fp == NULL) {
457476
printf("Failed to run command %s\n", shell_cmd);
477+
} else {
478+
pclose(fp);
458479
}
459480
break;
460481
case SACTION_BRIGHTNESS_UP:
@@ -468,6 +489,8 @@ void do_emu_action(void)
468489
fp = popen(shell_cmd, "r");
469490
if (fp == NULL) {
470491
printf("Failed to run command %s\n", shell_cmd);
492+
} else {
493+
pclose(fp);
471494
}
472495
break;
473496
case SACTION_MINIMIZE:

frontend/menu.c

Lines changed: 35 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -488,6 +488,7 @@ void init_menu_system_values(){
488488
volume_percentage = 50; ///wrong value: setting default to 50
489489
}
490490
else{
491+
pclose(fp);
491492
fgets(res, sizeof(res)-1, fp);
492493

493494
/// Check if Volume is a number (at least the first char)
@@ -508,6 +509,7 @@ void init_menu_system_values(){
508509
brightness_percentage = 50; ///wrong value: setting default to 50
509510
}
510511
else{
512+
pclose(fp);
511513
fgets(res, sizeof(res)-1, fp);
512514

513515
/// Check if brightness is a number (at least the first char)
@@ -767,7 +769,10 @@ void run_menu_loop()
767769
RES_HW_SCREEN_HORIZONTAL * RES_HW_SCREEN_VERTICAL * sizeof(u16));
768770

769771
/* Stop Ampli */
770-
popen(SHELL_CMD_TURN_AMPLI_OFF, "r");
772+
fp = popen(SHELL_CMD_TURN_AMPLI_OFF, "r");
773+
if (fp != NULL) {
774+
pclose(fp);
775+
}
771776

772777
/// ------ Wait for menu UP key event ------
773778
while(event.type != SDL_KEYUP || event.key.keysym.sym != SDLK_q){
@@ -860,6 +865,8 @@ void run_menu_loop()
860865
fp = popen(shell_cmd, "r");
861866
if (fp == NULL) {
862867
MENU_ERROR_PRINTF("Failed to run command %s\n", shell_cmd);
868+
} else {
869+
pclose(fp);
863870
}
864871

865872
/// ------ Refresh screen ------
@@ -876,6 +883,8 @@ void run_menu_loop()
876883
fp = popen(shell_cmd, "r");
877884
if (fp == NULL) {
878885
MENU_ERROR_PRINTF("Failed to run command %s\n", shell_cmd);
886+
} else {
887+
pclose(fp);
879888
}
880889
/// ------ Refresh screen ------
881890
screen_refresh = 1;
@@ -932,6 +941,8 @@ void run_menu_loop()
932941
fp = popen(shell_cmd, "r");
933942
if (fp == NULL) {
934943
MENU_ERROR_PRINTF("Failed to run command %s\n", shell_cmd);
944+
} else {
945+
pclose(fp);
935946
}
936947
/// ------ Refresh screen ------
937948
screen_refresh = 1;
@@ -947,6 +958,8 @@ void run_menu_loop()
947958
fp = popen(shell_cmd, "r");
948959
if (fp == NULL) {
949960
MENU_ERROR_PRINTF("Failed to run command %s\n", shell_cmd);
961+
} else {
962+
pclose(fp);
950963
}
951964
/// ------ Refresh screen ------
952965
screen_refresh = 1;
@@ -1013,6 +1026,8 @@ void run_menu_loop()
10131026
fp = popen(shell_cmd, "r");
10141027
if (fp == NULL) {
10151028
MENU_ERROR_PRINTF("Failed to run command %s\n", shell_cmd);
1029+
} else {
1030+
pclose(fp);
10161031
}
10171032

10181033
stop_menu_loop = 1;
@@ -1058,6 +1073,8 @@ void run_menu_loop()
10581073
fp = popen(shell_cmd, "r");
10591074
if (fp == NULL) {
10601075
MENU_ERROR_PRINTF("Failed to run command %s\n", shell_cmd);
1076+
} else {
1077+
pclose(fp);
10611078
}
10621079

10631080
stop_menu_loop = 1;
@@ -1161,7 +1178,10 @@ void run_menu_loop()
11611178
}
11621179

11631180
/* Start Ampli */
1164-
popen(SHELL_CMD_TURN_AMPLI_ON, "r");
1181+
fp = popen(SHELL_CMD_TURN_AMPLI_ON, "r");
1182+
if (fp != NULL) {
1183+
pclose(fp);
1184+
}
11651185

11661186
/// ------ Reset last screen ------
11671187
if(reset_last_scren_on_exit){
@@ -1191,9 +1211,13 @@ int launch_resume_menu_loop()
11911211
uint8_t screen_refresh = 1;
11921212
uint8_t menu_confirmation = 0;
11931213
int option_idx=RESUME_YES;
1214+
FILE *fp;
11941215

11951216
/* Stop Ampli */
1196-
popen(SHELL_CMD_TURN_AMPLI_OFF, "r");
1217+
fp = popen(SHELL_CMD_TURN_AMPLI_OFF, "r");
1218+
if (fp != NULL) {
1219+
pclose(fp);
1220+
}
11971221

11981222
/* Save prev key repeat params and set new Key repeat */
11991223
SDL_GetKeyRepeat(&backup_key_repeat_delay, &backup_key_repeat_interval);
@@ -1361,7 +1385,10 @@ int launch_resume_menu_loop()
13611385
}
13621386

13631387
/* Start Ampli */
1364-
popen(SHELL_CMD_TURN_AMPLI_ON, "r");
1388+
fp = popen(SHELL_CMD_TURN_AMPLI_ON, "r");
1389+
if (fp != NULL) {
1390+
pclose(fp);
1391+
}
13651392

13661393
return option_idx;
13671394
}
@@ -3193,6 +3220,8 @@ static void menu_bios_warn(void)
31933220
FILE *fp = popen(shell_cmd, "r");
31943221
if (fp == NULL) {
31953222
printf("In %s, Failed to run command %s\n", __func__, shell_cmd);
3223+
} else {
3224+
pclose(fp);
31963225
}
31973226

31983227
/// ------ Wait for key press ------
@@ -3206,6 +3235,8 @@ static void menu_bios_warn(void)
32063235
fp = popen(SHELL_CMD_NOTIF_CLEAR, "r");
32073236
if (fp == NULL) {
32083237
printf("In %s, Failed to run command %s\n", __func__, SHELL_CMD_NOTIF_CLEAR);
3238+
} else {
3239+
pclose(fp);
32093240
}
32103241
}
32113242

0 commit comments

Comments
 (0)