Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 095da0f6 authored by Greg Kaiser's avatar Greg Kaiser Committed by Martin Brabham
Browse files

[DO NOT MERGE] btif: Avoid resource leak in error case

If our memory allocation fails, we make sure we close our file
before returning.

Bug: b/117993149
Test: TreeHugger
Change-Id: I43b43d8b3d96e51a73bc8187ef614d02bbd31781
Merged-In: I43b43d8b3d96e51a73bc8187ef614d02bbd31781
parent d968f038
Loading
Loading
Loading
Loading
+4 −1
Original line number Diff line number Diff line
@@ -588,7 +588,10 @@ static std::string hash_file(const char* filename) {
  const int bufSize = 400 * 10;  // initial file is ~400B
  std::byte* buffer = (std::byte*) osi_calloc(bufSize);
  int bytesRead = 0;
  if (!buffer) return "";
  if (!buffer) {
    fclose(fp);
    return "";
  }
  while ((bytesRead = fread(buffer, 1, bufSize, fp))) {
    SHA256_Update(&sha256, buffer, bytesRead);
  }