Skip to content

Commit 938ebd0

Browse files
committed
add missing pclose()
Signed-off-by: Michel-FK <michel.stempin@funkey-project.com>
1 parent e5c8259 commit 938ebd0

3 files changed

Lines changed: 33 additions & 6 deletions

File tree

src/funkeymenu.cpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -411,6 +411,7 @@ void FunkeyMenu::init_menu_system_values(){
411411
volume_percentage = 50; ///wrong value: setting default to 50
412412
}
413413
else{
414+
pclose(fp);
414415
fgets(res, sizeof(res)-1, fp);
415416

416417
/// Check if Volume is a number (at least the first char)
@@ -431,6 +432,7 @@ void FunkeyMenu::init_menu_system_values(){
431432
brightness_percentage = 50; ///wrong value: setting default to 50
432433
}
433434
else{
435+
pclose(fp);
434436
fgets(res, sizeof(res)-1, fp);
435437

436438
/// Check if brightness is a number (at least the first char)
@@ -828,6 +830,8 @@ int FunkeyMenu::launch( )
828830
fp = popen(shell_cmd, "r");
829831
if (fp == NULL) {
830832
MENU_ERROR_PRINTF("Failed to run command %s\n", shell_cmd);
833+
} else {
834+
pclose(fp);
831835
}
832836

833837
/// ------ Refresh screen ------
@@ -844,6 +848,8 @@ int FunkeyMenu::launch( )
844848
fp = popen(shell_cmd, "r");
845849
if (fp == NULL) {
846850
MENU_ERROR_PRINTF("Failed to run command %s\n", shell_cmd);
851+
} else {
852+
pclose(fp);
847853
}
848854
/// ------ Refresh screen ------
849855
screen_refresh = 1;
@@ -889,6 +895,8 @@ int FunkeyMenu::launch( )
889895
fp = popen(shell_cmd, "r");
890896
if (fp == NULL) {
891897
MENU_ERROR_PRINTF("Failed to run command %s\n", shell_cmd);
898+
} else {
899+
pclose(fp);
892900
}
893901
/// ------ Refresh screen ------
894902
screen_refresh = 1;
@@ -904,6 +912,8 @@ int FunkeyMenu::launch( )
904912
fp = popen(shell_cmd, "r");
905913
if (fp == NULL) {
906914
MENU_ERROR_PRINTF("Failed to run command %s\n", shell_cmd);
915+
} else {
916+
pclose(fp);
907917
}
908918
/// ------ Refresh screen ------
909919
screen_refresh = 1;
@@ -982,6 +992,7 @@ int FunkeyMenu::launch( )
982992
MENU_ERROR_PRINTF("Failed to run command %s\n", shell_cmd);
983993
}
984994
else{
995+
pclose(fp);
985996
usb_sharing = !usb_sharing;
986997
}*/
987998

@@ -1053,6 +1064,8 @@ int FunkeyMenu::launch( )
10531064
fp = popen(shell_cmd, "r");
10541065
if (fp == NULL) {
10551066
MENU_ERROR_PRINTF("Failed to run command %s\n", shell_cmd);
1067+
} else {
1068+
pclose(fp);
10561069
}
10571070

10581071
return MENU_RETURN_EXIT;

src/gmenu2x.cpp

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -126,14 +126,19 @@ static void quit_all(int err) {
126126
/* Quick save and turn off the console */
127127
static void quick_poweroff()
128128
{
129-
/* Send command to cancel any previously scheduled powerdown */
130-
if (popen(SHELL_CMD_CANCEL_SCHED_POWERDOWN, "r") == NULL)
129+
FILE *fp;
130+
131+
/* Send command to cancel any previously scheduled powerdown */
132+
fp = popen(SHELL_CMD_CANCEL_SCHED_POWERDOWN, "r");
133+
if (fp == NULL)
131134
{
132135
/* Countdown is still ticking, so better do nothing
133136
than start writing and get interrupted!
134137
*/
135138
printf("Failed to cancel scheduled shutdown\n");
136139
exit(0);
140+
} else {
141+
pclose(fp);
137142
}
138143

139144
/* Perform Instant Play save and shutdown */
@@ -173,15 +178,20 @@ static void set_handler(int signal, void (*handler)(int))
173178
}
174179

175180
int main(int /*argc*/, char * /*argv*/[]) {
181+
FILE *fp;
182+
176183
INFO("---- GMenu2X starting ----\n");
177184

178185
set_handler(SIGINT, &quit_all);
179186
set_handler(SIGSEGV, &quit_all);
180187
set_handler(SIGTERM, &quit_all);
181188
set_handler(SIGUSR1, &handle_sigusr1);
182189

183-
/* Stop Ampli */
184-
popen(SHELL_CMD_TURN_AMPLI_OFF, "r");
190+
/* Stop Ampli */
191+
fp = popen(SHELL_CMD_TURN_AMPLI_OFF, "r");
192+
if (fp != NULL) {
193+
pclose(fp);
194+
}
185195

186196
char *home = getenv("HOME");
187197
if (home == NULL) {

src/launcher.cpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,13 @@ Launcher::Launcher(vector<string> && commandLine, bool consoleApp)
3232

3333
void Launcher::exec()
3434
{
35+
FILE *fp;
3536

36-
/* Start audio amp */
37-
popen(SHELL_CMD_TURN_AMPLI_ON, "r");
37+
/* Start audio amp */
38+
fp = popen(SHELL_CMD_TURN_AMPLI_ON, "r");
39+
if (fp != NULL) {
40+
pclose(fp);
41+
}
3842

3943
if (consoleApp) {
4044
#ifdef BIND_CONSOLE

0 commit comments

Comments
 (0)