Browse Source

SDL_zenitymessagebox.c: Add exit code checking.

Fixes https://github.com/libsdl-org/SDL/issues/14140
Closes https://github.com/libsdl-org/SDL/pull/14146

Co-authored-by: eafton <[email protected]>
Ozkan Sezer 1 week ago
parent
commit
3723913969
1 changed files with 10 additions and 4 deletions
  1. 10 4
      src/dialog/unix/SDL_zenitymessagebox.c

+ 10 - 4
src/dialog/unix/SDL_zenitymessagebox.c

@@ -75,6 +75,7 @@ bool SDL_get_zenity_version(int *major, int *minor)
 
 
 bool SDL_Zenity_ShowMessageBox(const SDL_MessageBoxData *messageboxdata, int *buttonID)
 bool SDL_Zenity_ShowMessageBox(const SDL_MessageBoxData *messageboxdata, int *buttonID)
 {
 {
+    int exit_code = -1;
     int zenity_major = 0, zenity_minor = 0, output_len = 0;
     int zenity_major = 0, zenity_minor = 0, output_len = 0;
     int argc = 5, i;
     int argc = 5, i;
     const char *argv[5 + 2 /* icon name */ + 2 /* title */ + 2 /* message */ + 2 * MAX_BUTTONS + 1 /* NULL */] = {
     const char *argv[5 + 2 /* icon name */ + 2 /* title */ + 2 /* message */ + 2 * MAX_BUTTONS + 1 /* NULL */] = {
@@ -158,8 +159,12 @@ bool SDL_Zenity_ShowMessageBox(const SDL_MessageBoxData *messageboxdata, int *bu
         return false;
         return false;
     }
     }
     if (buttonID) {
     if (buttonID) {
-        char *output = SDL_ReadProcess(process, NULL, NULL);
-        if (output) {
+        char *output = SDL_ReadProcess(process, NULL, &exit_code);
+        if (exit_code < 0 || exit_code == 255) {
+            if (output) {
+                SDL_free(output);
+            }
+        } else if (output) {
             // It likes to add a newline...
             // It likes to add a newline...
             char *tmp = SDL_strrchr(output, '\n');
             char *tmp = SDL_strrchr(output, '\n');
             if (tmp) {
             if (tmp) {
@@ -177,9 +182,10 @@ bool SDL_Zenity_ShowMessageBox(const SDL_MessageBoxData *messageboxdata, int *bu
             }
             }
             SDL_free(output);
             SDL_free(output);
         }
         }
+    } else {
+        SDL_WaitProcess(process, true, &exit_code);
     }
     }
     SDL_DestroyProcess(process);
     SDL_DestroyProcess(process);
 
 
-    return true;
+    return !(exit_code < 0 || exit_code == 255);
 }
 }
-