# # # patch "ChangeLog" # from [8a8cbd196d6e2bd2444e9a38c14046b88005b0fc] # to [3d9d3f9d25fe9dc2987e14f918cab4526730ad5d] # # patch "win32/process.cc" # from [ab93b7be4a7e9855b5441057f647bd95539bbb56] # to [c46b3a202b67753c4a8b36e7317668d9b5ee0e49] # ============================================================ --- ChangeLog 8a8cbd196d6e2bd2444e9a38c14046b88005b0fc +++ ChangeLog 3d9d3f9d25fe9dc2987e14f918cab4526730ad5d @@ -1,3 +1,8 @@ +2007-02-09 Matthew Gregan + + * win32/process.cc (process_spawn): Remove the manual memory + management and use a std::vector instead. + 2007-02-08 Matthew Gregan * win32/process.cc: Rework munge_argv_into_cmdline and its helpers ============================================================ --- win32/process.cc ab93b7be4a7e9855b5441057f647bd95539bbb56 +++ win32/process.cc c46b3a202b67753c4a8b36e7317668d9b5ee0e49 @@ -125,42 +125,36 @@ process_spawn(const char * const argv[]) pid_t process_spawn(const char * const argv[]) { - char * realexe, * filepart; - int realexelen; - std::string cmd, tmp1, tmp2; - std::string::iterator it; - STARTUPINFO si; - PROCESS_INFORMATION pi; + std::vector realexe; + realexe.resize(strlen(argv[0]) + 1 + MAXPATH); - realexelen = strlen(argv[0]) + 1 + MAX_PATH; - realexe = new char[realexelen]; - if (realexe == NULL) - return 0; - L(FL("searching for exe: %s\n") % argv[0]); - if (SearchPath(NULL, argv[0], ".exe", realexelen, realexe, &filepart) == 0) + L(FL("searching for exe: %s\n") % realexe); + char * filepart; + if (SearchPath(NULL, argv[0], ".exe", realexe.size(), &*realexe.begin(), &filepart) == 0) { os_err_t errnum = GetLastError(); L(FL("SearchPath failed, err=%s (%d)\n") % os_strerror(errnum) % errnum); - delete [] realexe; return -1; } - cmd = munge_argv_into_cmdline(argv); - L(FL("spawning command: '%s' '%s'\n") % realexe % cmd); + std::string cmd = munge_argv_into_cmdline(argv); + L(FL("spawning command: '%s' '%s'\n") % &*realexe.begin() % cmd); + STARTUPINFO si; + PROCESS_INFORMATION pi; + memset(&si, 0, sizeof(si)); si.cb = sizeof(STARTUPINFO); + /* We don't need to set any of the STARTUPINFO members */ - if (CreateProcess(realexe, (char *) cmd.c_str(), NULL, NULL, TRUE, 0, NULL, NULL, &si, &pi)==0) + if (CreateProcess(realexe, (char *) cmd.c_str(), NULL, NULL, TRUE, 0, NULL, NULL, &si, &pi) == 0) { os_err_t errnum = GetLastError(); L(FL("CreateProcess failed, err=%s (%d)\n") % os_strerror(errnum) % errnum); - delete [] realexe; return -1; } - delete [] realexe; CloseHandle(pi.hThread); - return (pid_t) pi.hProcess; + return static_cast(pi.hProcess); } struct redir @@ -187,10 +181,10 @@ redir::redir(int which, char const * fil sa.bInheritHandle = true; file = CreateFile(filename, - (which == 0 ? GENERIC_READ:GENERIC_WRITE), + (which == 0 ? GENERIC_READ : GENERIC_WRITE), FILE_SHARE_READ, &sa, - (which == 0 ? OPEN_EXISTING:CREATE_ALWAYS), + (which == 0 ? OPEN_EXISTING : CREATE_ALWAYS), FILE_ATTRIBUTE_NORMAL, NULL); switch(which)