@@ -58,38 +58,37 @@ std::wstring get_shell_path(std::wstring filename) {
58
58
return shellpath;
59
59
}
60
60
61
- wchar_t buffer_[MAX_ENV];
61
+ wchar_t * buffer_ = new wchar_t [MAX_ENV];
62
62
int read = ::GetEnvironmentVariableW (L" Path" , buffer_, MAX_ENV);
63
- if (!read ) {
64
- return shellpath;
65
- }
66
-
67
- std::wstring delimiter = L" ;" ;
68
- size_t pos = 0 ;
69
- std::vector<std::wstring> paths;
70
- std::wstring buffer (buffer_);
71
- while ((pos = buffer.find (delimiter)) != std::wstring::npos) {
72
- paths.push_back (buffer.substr (0 , pos));
73
- buffer.erase (0 , pos + delimiter.length ());
74
- }
63
+ if (read ) {
64
+ std::wstring delimiter = L" ;" ;
65
+ size_t pos = 0 ;
66
+ std::vector<std::wstring> paths;
67
+ std::wstring buffer (buffer_);
68
+ while ((pos = buffer.find (delimiter)) != std::wstring::npos) {
69
+ paths.push_back (buffer.substr (0 , pos));
70
+ buffer.erase (0 , pos + delimiter.length ());
71
+ }
75
72
76
- const wchar_t *filename_ = filename.c_str ();
73
+ const wchar_t *filename_ = filename.c_str ();
77
74
78
- for (size_t i = 0 ; i < paths.size (); ++i) {
79
- std::wstring path = paths[i];
80
- wchar_t searchPath[MAX_PATH];
81
- ::PathCombineW (searchPath, const_cast <wchar_t *>(path.c_str()), filename_);
75
+ for (size_t i = 0 ; i < paths.size (); ++i) {
76
+ std::wstring path = paths[i];
77
+ wchar_t searchPath[MAX_PATH];
78
+ ::PathCombineW (searchPath, const_cast <wchar_t *>(path.c_str()), filename_);
82
79
83
- if (searchPath == NULL ) {
84
- continue ;
85
- }
80
+ if (searchPath == NULL ) {
81
+ continue ;
82
+ }
86
83
87
- if (file_exists (searchPath)) {
88
- shellpath = searchPath;
89
- break ;
84
+ if (file_exists (searchPath)) {
85
+ shellpath = searchPath;
86
+ break ;
87
+ }
90
88
}
91
89
}
92
90
91
+ delete[] buffer_;
93
92
return shellpath;
94
93
}
95
94
0 commit comments