Browse Source

add missing pclose()

Signed-off-by: Michel-FK <michel.stempin@funkey-project.com>
Michel-FK 3 years ago
parent
commit
009d007fc9
2 changed files with 58 additions and 9 deletions
  1. 26 4
      platform/common/emu.c
  2. 32 5
      platform/common/menu_pico.c

+ 26 - 4
platform/common/emu.c

@@ -268,6 +268,8 @@ static const char *find_bios(int *region, const char *cd_fname)
 	    FILE *fp = popen(shell_cmd, "r");
 	    if (fp == NULL) {
 	        printf("In %s, Failed to run command %s\n", __func__, shell_cmd);
+	    } else {
+	        pclose(fp);
 	    }
 
 	    /** Wait for key press */
@@ -281,6 +283,8 @@ static const char *find_bios(int *region, const char *cd_fname)
 	    fp = popen(SHELL_CMD_NOTIF_CLEAR, "r");
 	    if (fp == NULL) {
 	        printf("In %s, Failed to run command %s\n", __func__, SHELL_CMD_NOTIF_CLEAR);
+	    } else {
+	        pclose(fp);
 	    }
 
 	    /** Force clean exit */
@@ -1249,6 +1253,8 @@ static void run_events_ui(unsigned int which)
 		fp = popen(shell_cmd, "r");
 		if (fp == NULL) {
 			printf("Failed to run command %s\n", shell_cmd);
+		} else {
+	        	pclose(fp);
 		}
 	}
 	if (which & PEV_VOL_UP)
@@ -1266,6 +1272,8 @@ static void run_events_ui(unsigned int which)
 		fp = popen(shell_cmd, "r");
 		if (fp == NULL) {
 			printf("Failed to run command %s\n", shell_cmd);
+		} else {
+	        	pclose(fp);
 		}
 	}
 	if (which & PEV_BRIGHT_UP)
@@ -1283,6 +1291,8 @@ static void run_events_ui(unsigned int which)
 		fp = popen(shell_cmd, "r");
 		if (fp == NULL) {
 			printf("Failed to run command %s\n", shell_cmd);
+		} else {
+	        	pclose(fp);
 		}
 	}
 	if (which & PEV_BRIGHT_DOWN)
@@ -1300,6 +1310,8 @@ static void run_events_ui(unsigned int which)
 		fp = popen(shell_cmd, "r");
 		if (fp == NULL) {
 			printf("Failed to run command %s\n", shell_cmd);
+		} else {
+	        	pclose(fp);
 		}
 	}
 	if (which & PEV_AR_FACT_UP)
@@ -1324,6 +1336,8 @@ static void run_events_ui(unsigned int which)
 		fp = popen(shell_cmd, "r");
 		if (fp == NULL) {
 			printf("Failed to run command %s\n", shell_cmd);
+		} else {
+	        	pclose(fp);
 		}
 
         // Save config file
@@ -1346,11 +1360,13 @@ static void run_events_ui(unsigned int which)
 		/*char txt[100];
 		sprintf(txt, "    DISPLAY MODE: ZOOMED - %d%%", aspect_ratio_factor_percent);
 		plat_status_msg_busy_first(txt);*/
-        sprintf(shell_cmd, "%s %d \"    DISPLAY MODE: ZOOMED %d%%%%\"",
+		sprintf(shell_cmd, "%s %d \"    DISPLAY MODE: ZOOMED %d%%%%\"",
 			SHELL_CMD_NOTIF, NOTIF_SECONDS_DISP, aspect_ratio_factor_percent);
-        fp = popen(shell_cmd, "r");
-        if (fp == NULL) {
+		fp = popen(shell_cmd, "r");
+		if (fp == NULL) {
 			printf("Failed to run command %s\n", shell_cmd);
+		} else {
+	        	pclose(fp);
 		}
 
         // Save config file
@@ -1378,6 +1394,8 @@ static void run_events_ui(unsigned int which)
 		fp = popen(shell_cmd, "r");
 		if (fp == NULL) {
 			printf("Failed to run command %s\n", shell_cmd);
+		} else {
+	        	pclose(fp);
 		}
 
         // Save config file
@@ -1492,10 +1510,13 @@ void emu_cmn_forced_frame(int no_scale, int do_emu, void *buf)
 /* Quick save and turn off the console */
 void quick_save_and_poweroff()
 {
+    FILE *fp;
+
     printf("Save Instant Play file\n");
 
     /* Send command to cancel any previously scheduled powerdown */
-    if (popen(SHELL_CMD_CANCEL_SCHED_POWERDOWN, "r") == NULL)
+    fp = popen(SHELL_CMD_CANCEL_SCHED_POWERDOWN, "r");
+    if (fp == NULL)
     {
         /* Countdown is still ticking, so better do nothing
 	   than start writing and get interrupted!
@@ -1503,6 +1524,7 @@ void quick_save_and_poweroff()
         printf("Failed to cancel scheduled shutdown\n");
 	exit(0);
     }
+    pclose(fp);
 
     /* Save  */
     emu_save_load_game_from_file(0, quick_save_file);

+ 32 - 5
platform/common/menu_pico.c

@@ -443,6 +443,7 @@ void init_menu_system_values(){
         volume_percentage = 50; ///wrong value: setting default to 50
     }
     else{
+        pclose(fp);
         fgets(res, sizeof(res)-1, fp);
 
         /// Check if Volume is a number (at least the first char)
@@ -463,6 +464,7 @@ void init_menu_system_values(){
         brightness_percentage = 50; ///wrong value: setting default to 50
     }
     else{
+        pclose(fp);
         fgets(res, sizeof(res)-1, fp);
 
         /// Check if brightness is a number (at least the first char)
@@ -707,7 +709,10 @@ void run_menu_loop()
             RES_HW_SCREEN_HORIZONTAL * RES_HW_SCREEN_VERTICAL * sizeof(uint16_t));
 
     /* Stop Ampli */
-    popen(SHELL_CMD_TURN_AMPLI_OFF, "r");
+    fp = popen(SHELL_CMD_TURN_AMPLI_OFF, "r");
+    if (fp != NULL) {
+        pclose(fp);
+    }
 
     /// ------ Wait for menu UP key event ------
     int actions[IN_BINDTYPE_COUNT] = { 0, };
@@ -800,7 +805,9 @@ void run_menu_loop()
                             fp = popen(shell_cmd, "r");
                             if (fp == NULL) {
                                 MENU_ERROR_PRINTF("Failed to run command %s\n", shell_cmd);
-                            }
+                            } else {
+			        pclose(fp);
+			    }
 
                             /// ------ Refresh screen ------
                             screen_refresh = 1;
@@ -816,6 +823,8 @@ void run_menu_loop()
                             fp = popen(shell_cmd, "r");
                             if (fp == NULL) {
                                 MENU_ERROR_PRINTF("Failed to run command %s\n", shell_cmd);
+                            } else {
+			        pclose(fp);
                             }
                         /// ------ Refresh screen ------
                             screen_refresh = 1;
@@ -872,6 +881,8 @@ void run_menu_loop()
                             fp = popen(shell_cmd, "r");
                             if (fp == NULL) {
                                 MENU_ERROR_PRINTF("Failed to run command %s\n", shell_cmd);
+                            } else {
+			        pclose(fp);
                             }
                             /// ------ Refresh screen ------
                             screen_refresh = 1;
@@ -887,6 +898,8 @@ void run_menu_loop()
                             fp = popen(shell_cmd, "r");
                             if (fp == NULL) {
                                 MENU_ERROR_PRINTF("Failed to run command %s\n", shell_cmd);
+                            } else {
+			        pclose(fp);
                             }
                             /// ------ Refresh screen ------
                             screen_refresh = 1;
@@ -953,6 +966,8 @@ void run_menu_loop()
                                 fp = popen(shell_cmd, "r");
                                 if (fp == NULL) {
                                     MENU_ERROR_PRINTF("Failed to run command %s\n", shell_cmd);
+				} else {
+				    pclose(fp);
                                 }
 
                                 stop_menu_loop = 1;
@@ -998,6 +1013,8 @@ void run_menu_loop()
                                 fp = popen(shell_cmd, "r");
                                 if (fp == NULL) {
                                     MENU_ERROR_PRINTF("Failed to run command %s\n", shell_cmd);
+				} else {
+				    pclose(fp);
                                 }
 
                                 /*snprintf(hud_msg, sizeof(hud_msg), ret == 0 ? "LOADED" : "FAIL!");
@@ -1095,7 +1112,10 @@ void run_menu_loop()
     }
 
     /* Start Ampli */
-    popen(SHELL_CMD_TURN_AMPLI_ON, "r");
+    fp = popen(SHELL_CMD_TURN_AMPLI_ON, "r");
+    if (fp != NULL) {
+        pclose(fp);
+    }
 
     /// ------ Reset last screen ------
     SDL_BlitSurface(backup_hw_screen, NULL, hw_screen, NULL);
@@ -1125,9 +1145,13 @@ int launch_resume_menu_loop()
     uint8_t screen_refresh = 1;
     uint8_t menu_confirmation = 0;
     int option_idx=RESUME_YES;
+    FILE *fp;
 
     /* Stop Ampli */
-    popen(SHELL_CMD_TURN_AMPLI_OFF, "r");
+    fp = popen(SHELL_CMD_TURN_AMPLI_OFF, "r");
+    if (fp != NULL) {
+        pclose(fp);
+    }
 
     /* Save prev key repeat params and set new Key repeat */
     SDL_GetKeyRepeat(&backup_key_repeat_delay, &backup_key_repeat_interval);
@@ -1296,7 +1320,10 @@ int launch_resume_menu_loop()
     }
 
     /* Start Ampli */
-    popen(SHELL_CMD_TURN_AMPLI_ON, "r");
+    fp = popen(SHELL_CMD_TURN_AMPLI_ON, "r");
+    if (fp != NULL) {
+        pclose(fp);
+    }
 
     return option_idx;
 }