diff --git a/client/cmdflashmem.c b/client/cmdflashmem.c index 34bb89cbc..cedb9516d 100644 --- a/client/cmdflashmem.c +++ b/client/cmdflashmem.c @@ -248,6 +248,7 @@ int CmdFlashMemLoad(const char *Cmd){ res = loadFile(filename, "bin", data, &datalen); //int res = loadFileEML( filename, "eml", data, &datalen); if ( res ) { + free(data); return 1; } @@ -607,4 +608,4 @@ int CmdHelp(const char *Cmd) { return 0; } -#endif \ No newline at end of file +#endif diff --git a/client/cmdhfmf.c b/client/cmdhfmf.c index fbd128bf4..4dd3b4b3e 100644 --- a/client/cmdhfmf.c +++ b/client/cmdhfmf.c @@ -2768,7 +2768,7 @@ int CmdHF14AMfCLoad(const char *Cmd) { // 64 or 256blocks. if (datalen != 1024 && datalen != 4096) { PrintAndLogEx(WARNING, "File content error. "); - free(data); + free(data); return 2; } diff --git a/client/loclass/fileutils.c b/client/loclass/fileutils.c index 6f6f1a5a4..f9d4db8d1 100644 --- a/client/loclass/fileutils.c +++ b/client/loclass/fileutils.c @@ -257,6 +257,7 @@ int loadFile(const char *preferredName, const char *suffix, void* data, size_t* if ( preferredName == NULL ) return 1; if ( suffix == NULL ) return 1; + if ( data == NULL ) return 1; int retval = 0; int size = sizeof(char) * (strlen(preferredName) + strlen(suffix) + 10); @@ -275,7 +276,7 @@ int loadFile(const char *preferredName, const char *suffix, void* data, size_t* long fsize = ftell(f); fseek(f, 0, SEEK_SET); - if ( fsize < 0 ) { + if ( fsize < 0 ) { PrintAndLogDevice(FAILED, "error, when getting filesize"); retval = 1; goto out; @@ -294,11 +295,7 @@ int loadFile(const char *preferredName, const char *suffix, void* data, size_t* PrintAndLogDevice(FAILED, "error, bytes read mismatch file size"); free(dump); retval = 3; - goto out; - } - - if ( (data) == NULL) { - (data) = calloc( bytes_read, sizeof(uint8_t)); + goto out; } memcpy( (data), dump, bytes_read); @@ -310,10 +307,6 @@ int loadFile(const char *preferredName, const char *suffix, void* data, size_t* out: fclose(f); - - if (data) - free(data); - free(fileName); return retval;