From 9ec144f4eab9599d83fd75b5b3e3e2634975f096 Mon Sep 17 00:00:00 2001 From: Pk11 Date: Wed, 18 Aug 2021 00:38:19 -0500 Subject: [PATCH] Fix resource leaks in calculateSHA1() --- arm9/source/fileOperations.cpp | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/arm9/source/fileOperations.cpp b/arm9/source/fileOperations.cpp index 9a18662..15861b7 100644 --- a/arm9/source/fileOperations.cpp +++ b/arm9/source/fileOperations.cpp @@ -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; }