Fix resource leaks in calculateSHA1()

This commit is contained in:
Pk11 2021-08-18 00:38:19 -05:00
parent 4fd905f894
commit 9ec144f4ea

View File

@ -96,7 +96,11 @@ bool calculateSHA1(const char *fileName, u8 *sha1) {
swiSHA1Update(&ctx, buf, ret);
scanKeys();
int keys = keysHeld();
if (keys & KEY_START) return false;
if (keys & KEY_START) {
free(buf);
fclose(fp);
return false;
}
font->print((ftell(fp) / (fsize / (SCREEN_COLS - 2))) + 1, nameHeight + 5, false, "=");
font->printf(0, nameHeight + 6, false, Alignment::left, Palette::white, "%d/%d bytes processed", ftell(fp), fsize);
@ -104,6 +108,7 @@ bool calculateSHA1(const char *fileName, u8 *sha1) {
}
swiSHA1Final(sha1, &ctx);
free(buf);
fclose(fp);
return true;
}