@@ -933,9 +933,9 @@ static pid_t mingw_spawnve_fd(const char *cmd, const char **argv, char **env,
933
933
{
934
934
STARTUPINFOW si ;
935
935
PROCESS_INFORMATION pi ;
936
- struct strbuf envblk , args ;
937
- wchar_t wcmd [MAX_PATH ], wdir [MAX_PATH ], * wargs ;
938
- unsigned flags ;
936
+ struct strbuf args ;
937
+ wchar_t wcmd [MAX_PATH ], wdir [MAX_PATH ], * wargs , * wenvblk = NULL ;
938
+ unsigned flags = CREATE_UNICODE_ENVIRONMENT ;
939
939
BOOL ret ;
940
940
941
941
/* Determine whether or not we are associated to a console */
@@ -952,15 +952,14 @@ static pid_t mingw_spawnve_fd(const char *cmd, const char **argv, char **env,
952
952
* instead of CREATE_NO_WINDOW to make ssh
953
953
* recognize that it has no console.
954
954
*/
955
- flags = DETACHED_PROCESS ;
955
+ flags | = DETACHED_PROCESS ;
956
956
} else {
957
957
/* There is already a console. If we specified
958
958
* DETACHED_PROCESS here, too, Windows would
959
959
* disassociate the child from the console.
960
960
* The same is true for CREATE_NO_WINDOW.
961
961
* Go figure!
962
962
*/
963
- flags = 0 ;
964
963
CloseHandle (cons );
965
964
}
966
965
memset (& si , 0 , sizeof (si ));
@@ -999,6 +998,7 @@ static pid_t mingw_spawnve_fd(const char *cmd, const char **argv, char **env,
999
998
if (env ) {
1000
999
int count = 0 ;
1001
1000
char * * e , * * sorted_env ;
1001
+ int size = 0 , wenvsz = 0 , wenvpos = 0 ;
1002
1002
1003
1003
for (e = env ; * e ; e ++ )
1004
1004
count ++ ;
@@ -1008,20 +1008,22 @@ static pid_t mingw_spawnve_fd(const char *cmd, const char **argv, char **env,
1008
1008
memcpy (sorted_env , env , sizeof (* sorted_env ) * (count + 1 ));
1009
1009
qsort (sorted_env , count , sizeof (* sorted_env ), env_compare );
1010
1010
1011
- strbuf_init ( & envblk , 0 );
1011
+ /* create environment block from temporary environment */
1012
1012
for (e = sorted_env ; * e ; e ++ ) {
1013
- strbuf_addstr (& envblk , * e );
1014
- strbuf_addch (& envblk , '\0' );
1013
+ size = 2 * strlen (* e ) + 2 ; /* +2 for final \0 */
1014
+ ALLOC_GROW (wenvblk , (wenvpos + size ) * sizeof (wchar_t ), wenvsz );
1015
+ wenvpos += xutftowcs (& wenvblk [wenvpos ], * e , size ) + 1 ;
1015
1016
}
1017
+ /* add final \0 terminator */
1018
+ wenvblk [wenvpos ] = 0 ;
1016
1019
free (sorted_env );
1017
1020
}
1018
1021
1019
1022
memset (& pi , 0 , sizeof (pi ));
1020
1023
ret = CreateProcessW (wcmd , wargs , NULL , NULL , TRUE, flags ,
1021
- env ? envblk . buf : NULL , dir ? wdir : NULL , & si , & pi );
1024
+ wenvblk , dir ? wdir : NULL , & si , & pi );
1022
1025
1023
- if (env )
1024
- strbuf_release (& envblk );
1026
+ free (wenvblk );
1025
1027
free (wargs );
1026
1028
1027
1029
if (!ret ) {
0 commit comments