stop leaking FILE* objects when hashing
authorPhilipp Gesang <philipp.gesang@intra2net.com>
Tue, 27 Nov 2018 15:30:41 +0000 (16:30 +0100)
committerThomas Jarosch <thomas.jarosch@intra2net.com>
Tue, 18 Dec 2018 11:57:30 +0000 (12:57 +0100)
In hash_file(), the input FILE* needs freeing when no error
occurred. Do this as soon as it is not needed anymore.

src/crypto.cpp

index d08f5d6..2aeb614 100644 (file)
@@ -168,9 +168,10 @@ string I2n::hash_file(string filename, algorithm algo)
         }
     }
 
+    fclose(file);
+
     if (!EVP_DigestFinal_ex(ctx.get(), ret.get(), &olen))
     {
-        fclose(file);
         throw runtime_error(ERROR_MESSAGE);
     }