mirror of
https://github.com/RfidResearchGroup/proxmark3.git
synced 2025-08-22 06:13:51 -07:00
fix memleak on realloc and uninit variable
This commit is contained in:
parent
f96361f8f1
commit
dded3953ef
1 changed files with 6 additions and 4 deletions
|
@ -955,7 +955,7 @@ static int l_T55xx_readblock(lua_State *L) {
|
||||||
if (n != 4)
|
if (n != 4)
|
||||||
return returnToLuaWithError(L, "Wrong number of arguments, got %d bytes, expected 4", n);
|
return returnToLuaWithError(L, "Wrong number of arguments, got %d bytes, expected 4", n);
|
||||||
|
|
||||||
uint32_t block, usepage1, override, password;
|
uint32_t block, usepage1, override, password = 0;
|
||||||
bool usepwd;
|
bool usepwd;
|
||||||
size_t size;
|
size_t size;
|
||||||
|
|
||||||
|
@ -1179,15 +1179,17 @@ static int l_cwd(lua_State *L) {
|
||||||
|
|
||||||
uint16_t path_len = FILENAME_MAX; // should be a good starting point
|
uint16_t path_len = FILENAME_MAX; // should be a good starting point
|
||||||
bool error = false;
|
bool error = false;
|
||||||
char *cwd = NULL;
|
char *cwd = (char *)calloc(path_len, sizeof(uint8_t));
|
||||||
cwd = (char *)calloc(path_len, sizeof(uint8_t));
|
|
||||||
|
|
||||||
while (!error && (GetCurrentDir(cwd, path_len) == NULL)) {
|
while (!error && (GetCurrentDir(cwd, path_len) == NULL)) {
|
||||||
if (errno == ERANGE) { // Need bigger buffer
|
if (errno == ERANGE) { // Need bigger buffer
|
||||||
path_len += 10; // if buffer was too small add 10 characters and try again
|
path_len += 10; // if buffer was too small add 10 characters and try again
|
||||||
cwd = realloc(cwd, path_len);
|
cwd = realloc(cwd, path_len);
|
||||||
|
if (cwd == NULL) {
|
||||||
|
free(cwd);
|
||||||
|
return returnToLuaWithError(L, "Failed to allocate memory");
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
error = true;
|
|
||||||
free(cwd);
|
free(cwd);
|
||||||
return returnToLuaWithError(L, "Failed to get current working directory");
|
return returnToLuaWithError(L, "Failed to get current working directory");
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue