From 3723913969dbb97e302949ecd84c16754d410b02 Mon Sep 17 00:00:00 2001 From: Ozkan Sezer Date: Sun, 5 Oct 2025 04:30:30 +0300 Subject: [PATCH] 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 --- src/dialog/unix/SDL_zenitymessagebox.c | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/src/dialog/unix/SDL_zenitymessagebox.c b/src/dialog/unix/SDL_zenitymessagebox.c index 0701b0418e..39d44f8517 100644 --- a/src/dialog/unix/SDL_zenitymessagebox.c +++ b/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) { + int exit_code = -1; int zenity_major = 0, zenity_minor = 0, output_len = 0; int argc = 5, i; 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; } 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... char *tmp = SDL_strrchr(output, '\n'); if (tmp) { @@ -177,9 +182,10 @@ bool SDL_Zenity_ShowMessageBox(const SDL_MessageBoxData *messageboxdata, int *bu } SDL_free(output); } + } else { + SDL_WaitProcess(process, true, &exit_code); } SDL_DestroyProcess(process); - return true; + return !(exit_code < 0 || exit_code == 255); } -