fileutils: clear *pdata after freeing it on a load error

loadFile_safeEx, loadFile_TXTsafe, loadFileEML_safe and loadFileMCT_safe
freed *pdata on a short read or a failed realloc but left the caller's
pointer set, so a caller keeping it freed it again. Same as
loadFileDICTIONARY_safe_ex already does.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
iceman1001andClaude Opus 5.5 committed 2026-11-09 15:05:52 +07:00
1 parent d11643c8f2
commit 81a9807c39
1 file changed
+4
+4
View File
@@ -1973,6 +1973,7 @@ int loadFile_safeEx(const char *preferredName, const char *suffix, void **pdata,
if (bytes_read != fsize) {
PrintAndLogEx(FAILED, "error, bytes read mismatch file size");
free(*pdata);
*pdata = NULL;
return PM3_EFILE;
}
@@ -2025,6 +2026,7 @@ int loadFile_TXTsafe(const char *preferredName, const char *suffix, void **pdata
if (bytes_read != fsize) {
PrintAndLogEx(FAILED, "error, bytes read mismatch file size");
free(*pdata);
*pdata = NULL;
return PM3_EFILE;
}
@@ -2112,6 +2114,7 @@ int loadFileEML_safe(const char *preferredName, void **pdata, size_t *datalen) {
if (newdump == NULL) {
PrintAndLogEx(WARNING, "Failed to allocate memory");
free(*pdata);
*pdata = NULL;
return PM3_EMALLOC;
} else {
*pdata = newdump;
@@ -2591,6 +2594,7 @@ int loadFileMCT_safe(const char *preferredName, void **pdata, size_t *datalen) {
if (newdump == NULL) {
PrintAndLogEx(WARNING, "Failed to allocate memory");
free(*pdata);
*pdata = NULL;
return PM3_EMALLOC;
} else {
*pdata = newdump;