Jelajahi Sumber

Prevent possible assert fail on windows in handle_cgi_request()

Sergey Lyubka 12 tahun lalu
induk
melakukan
d883b0f0f9
1 mengubah file dengan 9 tambahan dan 7 penghapusan
  1. 9 7
      mongoose.c

+ 9 - 7
mongoose.c

@@ -3110,7 +3110,15 @@ static void handle_cgi_request(struct mg_connection *conn, const char *prog) {
     send_http_error(conn, 500, http_500_error,
         "Cannot spawn CGI process [%s]: %s", prog, strerror(ERRNO));
     goto done;
-  } else if ((in = fdopen(fd_stdin[1], "wb")) == NULL ||
+  }
+
+  // spawn_process() must close those!
+  // If we don't mark them as closed, close() attempt before
+  // return from this function throws an exception on Windows.
+  // Windows does not like when closed descriptor is closed again.
+  fd_stdin[0] = fd_stdout[1] = -1;
+
+  if ((in = fdopen(fd_stdin[1], "wb")) == NULL ||
       (out = fdopen(fd_stdout[0], "rb")) == NULL) {
     send_http_error(conn, 500, http_500_error,
         "fopen: %s", strerror(ERRNO));
@@ -3120,12 +3128,6 @@ static void handle_cgi_request(struct mg_connection *conn, const char *prog) {
   setbuf(in, NULL);
   setbuf(out, NULL);
 
-  // spawn_process() must close those!
-  // If we don't mark them as closed, close() attempt before
-  // return from this function throws an exception on Windows.
-  // Windows does not like when closed descriptor is closed again.
-  fd_stdin[0] = fd_stdout[1] = -1;
-
   // Send POST data to the CGI process if needed
   if (!strcmp(conn->request_info.request_method, "POST") &&
       !forward_body_data(conn, in, INVALID_SOCKET, NULL)) {