mirror of
https://github.com/decompals/wibo.git
synced 2025-10-15 14:45:12 +00:00
cleanup memory leak fix
This commit is contained in:
parent
d3e6da54e3
commit
6b4f27a888
@ -102,11 +102,9 @@ namespace msvcrt {
|
|||||||
|
|
||||||
// allocate a copy on the heap,
|
// allocate a copy on the heap,
|
||||||
// since wStr will go out of scope
|
// since wStr will go out of scope
|
||||||
uint16_t* theActualStr = new uint16_t[wStr.size() + 1];
|
(*wargv)[i] = new uint16_t[wStr.size() + 1];
|
||||||
std::copy(wStr.begin(), wStr.end(), theActualStr);
|
std::copy(wStr.begin(), wStr.end(), (*wargv)[i]);
|
||||||
theActualStr[wStr.size()] = 0;
|
(*wargv)[i][wStr.size()] = 0;
|
||||||
|
|
||||||
(*wargv)[i] = theActualStr;
|
|
||||||
}
|
}
|
||||||
(*wargv)[argc] = nullptr;
|
(*wargv)[argc] = nullptr;
|
||||||
}
|
}
|
||||||
@ -124,11 +122,9 @@ namespace msvcrt {
|
|||||||
|
|
||||||
// allocate a copy on the heap,
|
// allocate a copy on the heap,
|
||||||
// since wStr will go out of scope
|
// since wStr will go out of scope
|
||||||
uint16_t* theActualStr = new uint16_t[wStr.size() + 1];
|
(*wenv)[i] = new uint16_t[wStr.size() + 1];
|
||||||
std::copy(wStr.begin(), wStr.end(), theActualStr);
|
std::copy(wStr.begin(), wStr.end(), (*wenv)[i]);
|
||||||
theActualStr[wStr.size()] = 0;
|
(*wenv)[i][wStr.size()] = 0;
|
||||||
|
|
||||||
(*wenv)[i] = theActualStr;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
(*wenv)[count] = nullptr;
|
(*wenv)[count] = nullptr;
|
||||||
@ -155,11 +151,11 @@ namespace msvcrt {
|
|||||||
|
|
||||||
size_t varnamelen = wstrlen(varname);
|
size_t varnamelen = wstrlen(varname);
|
||||||
|
|
||||||
DEBUG_LOG("\tSearching env vars...\n");
|
// DEBUG_LOG("\tSearching env vars...\n");
|
||||||
for(uint16_t** env = __winitenv; env && *env; ++env){
|
for(uint16_t** env = __winitenv; env && *env; ++env){
|
||||||
uint16_t* cur = *env;
|
uint16_t* cur = *env;
|
||||||
std::string cur_str = wideStringToString(cur);
|
std::string cur_str = wideStringToString(cur);
|
||||||
DEBUG_LOG("\tCur env var: %s\n", cur_str.c_str());
|
// DEBUG_LOG("\tCur env var: %s\n", cur_str.c_str());
|
||||||
if(wstrncmp(cur, varname, varnamelen) == 0 && cur[varnamelen] == L'='){
|
if(wstrncmp(cur, varname, varnamelen) == 0 && cur[varnamelen] == L'='){
|
||||||
DEBUG_LOG("Found the env var %s!\n", var_str.c_str());
|
DEBUG_LOG("Found the env var %s!\n", var_str.c_str());
|
||||||
uint16_t* value = cur + varnamelen + 1;
|
uint16_t* value = cur + varnamelen + 1;
|
||||||
@ -190,6 +186,7 @@ namespace msvcrt {
|
|||||||
for(uint16_t** env = __winitenv; env && *env; ++env){
|
for(uint16_t** env = __winitenv; env && *env; ++env){
|
||||||
uint16_t* cur = *env;
|
uint16_t* cur = *env;
|
||||||
std::string cur_str = wideStringToString(cur);
|
std::string cur_str = wideStringToString(cur);
|
||||||
|
DEBUG_LOG("\tCur env var: %s\n", cur_str.c_str());
|
||||||
if(wstrncmp(cur, varname, varnamelen) == 0 && cur[varnamelen] == L'='){
|
if(wstrncmp(cur, varname, varnamelen) == 0 && cur[varnamelen] == L'='){
|
||||||
uint16_t* value = cur + varnamelen + 1;
|
uint16_t* value = cur + varnamelen + 1;
|
||||||
size_t value_len = wstrlen(value);
|
size_t value_len = wstrlen(value);
|
||||||
@ -296,7 +293,7 @@ namespace msvcrt {
|
|||||||
}
|
}
|
||||||
|
|
||||||
uint16_t* WIN_ENTRY _wcsdup(const uint16_t *strSource){
|
uint16_t* WIN_ENTRY _wcsdup(const uint16_t *strSource){
|
||||||
std::string src_str = wideStringToString(strSource);
|
// std::string src_str = wideStringToString(strSource);
|
||||||
// DEBUG_LOG("_wcsdup: %s", src_str.c_str());
|
// DEBUG_LOG("_wcsdup: %s", src_str.c_str());
|
||||||
if(!strSource) return nullptr;
|
if(!strSource) return nullptr;
|
||||||
size_t strLen = wstrlen(strSource);
|
size_t strLen = wstrlen(strSource);
|
||||||
@ -308,7 +305,7 @@ namespace msvcrt {
|
|||||||
dup[i] = strSource[i];
|
dup[i] = strSource[i];
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string dst_str = wideStringToString(dup);
|
// std::string dst_str = wideStringToString(dup);
|
||||||
// DEBUG_LOG(" --> %s\n", dst_str.c_str());
|
// DEBUG_LOG(" --> %s\n", dst_str.c_str());
|
||||||
return dup;
|
return dup;
|
||||||
}
|
}
|
||||||
@ -325,7 +322,7 @@ namespace msvcrt {
|
|||||||
|
|
||||||
int WIN_ENTRY wcsncpy_s(uint16_t *strDest, size_t numberOfElements, const uint16_t *strSource, size_t count){
|
int WIN_ENTRY wcsncpy_s(uint16_t *strDest, size_t numberOfElements, const uint16_t *strSource, size_t count){
|
||||||
std::string src_str = wideStringToString(strSource);
|
std::string src_str = wideStringToString(strSource);
|
||||||
DEBUG_LOG("wcsncpy_s dest size %d, src str %s, src size %d", numberOfElements, src_str.c_str(), count);
|
DEBUG_LOG("wcsncpy_s dest size %d, src str %s, src size %d\n", numberOfElements, src_str.c_str(), count);
|
||||||
|
|
||||||
if(!strDest || !strSource || numberOfElements == 0){
|
if(!strDest || !strSource || numberOfElements == 0){
|
||||||
if(strDest && numberOfElements > 0) strDest[0] = L'\0';
|
if(strDest && numberOfElements > 0) strDest[0] = L'\0';
|
||||||
@ -341,8 +338,8 @@ namespace msvcrt {
|
|||||||
|
|
||||||
wstrncpy(strDest, strSource, count);
|
wstrncpy(strDest, strSource, count);
|
||||||
strDest[count] = L'\0';
|
strDest[count] = L'\0';
|
||||||
std::string dst_str = wideStringToString(strDest);
|
// std::string dst_str = wideStringToString(strDest);
|
||||||
DEBUG_LOG(" --> %s\n", dst_str.c_str());
|
// DEBUG_LOG(" --> %s\n", dst_str.c_str());
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user