mirror of
https://github.com/decompals/wibo.git
synced 2025-10-16 07:05:11 +00:00
get memory leaked nerd
This commit is contained in:
parent
4c9918ff2a
commit
d3e6da54e3
@ -97,8 +97,16 @@ namespace msvcrt {
|
|||||||
*wargv = new uint16_t*[argc + 1]; // allocate array of our future wstrings
|
*wargv = new uint16_t*[argc + 1]; // allocate array of our future wstrings
|
||||||
for(int i = 0; i < argc; i++){
|
for(int i = 0; i < argc; i++){
|
||||||
const char* cur_arg = argv[i];
|
const char* cur_arg = argv[i];
|
||||||
|
|
||||||
std::vector<uint16_t> wStr = stringToWideString(cur_arg);
|
std::vector<uint16_t> wStr = stringToWideString(cur_arg);
|
||||||
(*wargv)[i] = wStr.data();
|
|
||||||
|
// allocate a copy on the heap,
|
||||||
|
// since wStr will go out of scope
|
||||||
|
uint16_t* theActualStr = new uint16_t[wStr.size() + 1];
|
||||||
|
std::copy(wStr.begin(), wStr.end(), theActualStr);
|
||||||
|
theActualStr[wStr.size()] = 0;
|
||||||
|
|
||||||
|
(*wargv)[i] = theActualStr;
|
||||||
}
|
}
|
||||||
(*wargv)[argc] = nullptr;
|
(*wargv)[argc] = nullptr;
|
||||||
}
|
}
|
||||||
@ -108,12 +116,21 @@ namespace msvcrt {
|
|||||||
for(; env[count] != nullptr; count++);
|
for(; env[count] != nullptr; count++);
|
||||||
DEBUG_LOG("Found env count %d\n", count);
|
DEBUG_LOG("Found env count %d\n", count);
|
||||||
*wenv = new uint16_t*[count + 1]; // allocate array of our future wstrings
|
*wenv = new uint16_t*[count + 1]; // allocate array of our future wstrings
|
||||||
for(int i = 0; i < count; i++){
|
for (int i = 0; i < count; i++) {
|
||||||
const char* cur_env = env[i];
|
const char* cur_env = env[i];
|
||||||
DEBUG_LOG("Adding env %s\n", cur_env);
|
DEBUG_LOG("Adding env %s\n", cur_env);
|
||||||
std::vector<uint16_t> wStr = stringToWideString(cur_env);
|
|
||||||
(*wenv)[i] = wStr.data();
|
std::vector<uint16_t> wStr = stringToWideString(cur_env);
|
||||||
|
|
||||||
|
// allocate a copy on the heap,
|
||||||
|
// since wStr will go out of scope
|
||||||
|
uint16_t* theActualStr = new uint16_t[wStr.size() + 1];
|
||||||
|
std::copy(wStr.begin(), wStr.end(), theActualStr);
|
||||||
|
theActualStr[wStr.size()] = 0;
|
||||||
|
|
||||||
|
(*wenv)[i] = theActualStr;
|
||||||
}
|
}
|
||||||
|
|
||||||
(*wenv)[count] = nullptr;
|
(*wenv)[count] = nullptr;
|
||||||
|
|
||||||
__winitenv = *wenv;
|
__winitenv = *wenv;
|
||||||
@ -355,12 +372,19 @@ namespace msvcrt {
|
|||||||
|
|
||||||
int WIN_ENTRY _itow_s(int value, uint16_t *buffer, size_t size, int radix){
|
int WIN_ENTRY _itow_s(int value, uint16_t *buffer, size_t size, int radix){
|
||||||
DEBUG_LOG("_itow_s value %d, size %d, radix %d\n", value, size, radix);
|
DEBUG_LOG("_itow_s value %d, size %d, radix %d\n", value, size, radix);
|
||||||
if (!buffer || size == 0) return -1;
|
if (!buffer || size == 0) return 22;
|
||||||
assert(radix == 10); // only base 10 supported for now
|
assert(radix == 10); // only base 10 supported for now
|
||||||
|
|
||||||
std::string str = std::to_string(value);
|
std::string str = std::to_string(value);
|
||||||
std::vector<uint16_t> wstr = stringToWideString(str.c_str());
|
std::vector<uint16_t> wStr = stringToWideString(str.c_str());
|
||||||
wstrcpy(buffer, wstr.data());
|
|
||||||
|
if(wStr.size() + 1 > size){
|
||||||
|
buffer[0] = 0;
|
||||||
|
return 34;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::copy(wStr.begin(), wStr.end(), buffer);
|
||||||
|
buffer[wStr.size()] = 0;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user