Apply suggestions from @henrygab
Check if memory allocation fails Fix memory leak Initialize struct in declaration Add/Fix some notes Remove unlikely() in favor of readability Remove a hard-coded magic number
This commit is contained in:
12 files changed
+113
-44
No files matched your search
@@ -118,6 +118,10 @@ int demodHID(bool verbose) {
|
||||
uint32_t hi2 = 0, hi = 0, lo = 0;
|
||||
|
||||
uint8_t *bits = malloc(g_GraphTraceLen);
|
||||
if (bits == NULL) {
|
||||
PrintAndLogEx(FAILED, "failed to allocate memory");
|
||||
return PM3_EMALLOC;
|
||||
}
|
||||
size_t size = getFromGraphBuf(bits);
|
||||
if (size == 0) {
|
||||
PrintAndLogEx(DEBUG, "DEBUG: Error - " _RED_("HID not enough samples"));
|
||||
@@ -142,6 +146,7 @@ int demodHID(bool verbose) {
|
||||
else
|
||||
PrintAndLogEx(DEBUG, "DEBUG: Error - " _RED_("HID error demoding fsk %d"), idx);
|
||||
|
||||
free(bits);
|
||||
return PM3_ESOFT;
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user