mirror of
https://github.com/RfidResearchGroup/proxmark3.git
synced 2025-08-22 06:13:51 -07:00
fix another realloc
This commit is contained in:
parent
17c9bc8fc2
commit
036544e49e
1 changed files with 8 additions and 2 deletions
|
@ -57,15 +57,18 @@ static void fPrintAndLog(FILE *stream, const char *fmt, ...);
|
||||||
int searchHomeFilePath(char **foundpath, const char *subdir, const char *filename, bool create_home) {
|
int searchHomeFilePath(char **foundpath, const char *subdir, const char *filename, bool create_home) {
|
||||||
if (foundpath == NULL)
|
if (foundpath == NULL)
|
||||||
return PM3_EINVARG;
|
return PM3_EINVARG;
|
||||||
|
|
||||||
const char *user_path = get_my_user_directory();
|
const char *user_path = get_my_user_directory();
|
||||||
if (user_path == NULL) {
|
if (user_path == NULL) {
|
||||||
fprintf(stderr, "Could not retrieve $HOME from the environment\n");
|
fprintf(stderr, "Could not retrieve $HOME from the environment\n");
|
||||||
return PM3_EFILE;
|
return PM3_EFILE;
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t pathlen = strlen(user_path) + strlen(PM3_USER_DIRECTORY) + 1;
|
size_t pathlen = strlen(user_path) + strlen(PM3_USER_DIRECTORY) + 1;
|
||||||
char *path = calloc(pathlen, sizeof(char));
|
char *path = calloc(pathlen, sizeof(char));
|
||||||
if (path == NULL)
|
if (path == NULL)
|
||||||
return PM3_EMALLOC;
|
return PM3_EMALLOC;
|
||||||
|
|
||||||
strcpy(path, user_path);
|
strcpy(path, user_path);
|
||||||
strcat(path, PM3_USER_DIRECTORY);
|
strcat(path, PM3_USER_DIRECTORY);
|
||||||
|
|
||||||
|
@ -139,9 +142,12 @@ int searchHomeFilePath(char **foundpath, const char *subdir, const char *filenam
|
||||||
return PM3_SUCCESS;
|
return PM3_SUCCESS;
|
||||||
}
|
}
|
||||||
pathlen += strlen(filename);
|
pathlen += strlen(filename);
|
||||||
path = realloc(path, pathlen * sizeof(char));
|
char *tmp = realloc(path, pathlen * sizeof(char));
|
||||||
if (path == NULL)
|
if (tmp == NULL) {
|
||||||
|
free(path);
|
||||||
return PM3_EMALLOC;
|
return PM3_EMALLOC;
|
||||||
|
}
|
||||||
|
path = tmp;
|
||||||
strcat(path, filename);
|
strcat(path, filename);
|
||||||
*foundpath = path;
|
*foundpath = path;
|
||||||
return PM3_SUCCESS;
|
return PM3_SUCCESS;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue