[glib: 1/4] gspawn: Fix errno saving in Windows implementation



commit f4d2051fc13ff18af0d8cb8bed31115976f0aac8
Author: Philip Withnall <withnall endlessm com>
Date:   Tue Jun 12 15:33:35 2018 +0100

    gspawn: Fix errno saving in Windows implementation
    
    The error number was saved after some g_debug() and g_free() calls, in
    various places, which meant it could have been overwritten since the
    error we care about happened.
    
    https://gitlab.gnome.org/GNOME/glib/issues/303
    
    Signed-off-by: Philip Withnall <withnall endlessm com>

 glib/gspawn-win32.c | 22 +++++++++++-----------
 1 file changed, 11 insertions(+), 11 deletions(-)
---
diff --git a/glib/gspawn-win32.c b/glib/gspawn-win32.c
index 636e9ebe8..7b2451161 100644
--- a/glib/gspawn-win32.c
+++ b/glib/gspawn-win32.c
@@ -316,6 +316,7 @@ read_helper_report (int      fd,
   while (bytes < sizeof(gintptr)*2)
     {
       gint chunk;
+      int errsv;
 
       if (debug)
        g_print ("%s:read_helper_report: read %" G_GSIZE_FORMAT "...\n",
@@ -324,14 +325,13 @@ read_helper_report (int      fd,
 
       chunk = read (fd, ((gchar*)report) + bytes,
                    sizeof(gintptr)*2 - bytes);
+      errsv = errno;
 
       if (debug)
        g_print ("...got %d bytes\n", chunk);
           
       if (chunk < 0)
         {
-          int errsv = errno;
-
           /* Some weird shit happened, bail out */
           g_set_error (error, G_SPAWN_ERROR, G_SPAWN_ERROR_FAILED,
                        _("Failed to read from child pipe (%s)"),
@@ -429,7 +429,7 @@ do_spawn_directly (gint                 *exit_status,
   const int mode = (exit_status == NULL) ? P_NOWAIT : P_WAIT;
   char **new_argv;
   gintptr rc = -1;
-  int saved_errno;
+  int errsv;
   GError *conv_error = NULL;
   gint conv_error_index;
   wchar_t *wargv0, **wargv, **wenvp;
@@ -481,17 +481,17 @@ do_spawn_directly (gint                 *exit_status,
     else
       rc = _wspawnv (mode, wargv0, (const wchar_t **) wargv);
 
+  errsv = errno;
+
   g_free (wargv0);
   g_strfreev ((gchar **) wargv);
   g_strfreev ((gchar **) wenvp);
 
-  saved_errno = errno;
-
-  if (rc == -1 && saved_errno != 0)
+  if (rc == -1 && errsv != 0)
     {
       g_set_error (error, G_SPAWN_ERROR, G_SPAWN_ERROR_FAILED,
                   _("Failed to execute child process (%s)"),
-                  g_strerror (saved_errno));
+                  g_strerror (errsv));
       return FALSE;
     }
 
@@ -532,7 +532,7 @@ do_spawn_with_pipes (gint                 *exit_status,
   char **new_argv;
   int i;
   gintptr rc = -1;
-  int saved_errno;
+  int errsv;
   int argc;
   int stdin_pipe[2] = { -1, -1 };
   int stdout_pipe[2] = { -1, -1 };
@@ -752,7 +752,7 @@ do_spawn_with_pipes (gint                 *exit_status,
   else
     rc = _wspawnvp (P_NOWAIT, whelper, (const wchar_t **) wargv);
 
-  saved_errno = errno;
+  errsv = errno;
 
   g_free (whelper);
   g_strfreev ((gchar **) wargv);
@@ -774,11 +774,11 @@ do_spawn_with_pipes (gint                 *exit_status,
   g_free (new_argv);
 
   /* Check if gspawn-win32-helper couldn't be run */
-  if (rc == -1 && saved_errno != 0)
+  if (rc == -1 && errsv != 0)
     {
       g_set_error (error, G_SPAWN_ERROR, G_SPAWN_ERROR_FAILED,
                   _("Failed to execute helper program (%s)"),
-                  g_strerror (saved_errno));
+                  g_strerror (errsv));
       goto cleanup_and_fail;
     }
 


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]