Last active
March 29, 2019 22:38
-
-
Save patrickfav/8e9139eb6d7a99a2dcd4703e0bd00a99 to your computer and use it in GitHub Desktop.
Very simple test for probable Memory Leak in Bcrypt Library
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.ArrayList; | |
import java.util.List; | |
import java.util.Random; | |
public class Tester { | |
public static String[] pws = {"ZeDRJ:_tu:", "ZeDRJ:_tu1", "ZeDRJ:_tu2", "ZeDRJ:_tu3", "ZeDRJ:_tu4", "ZeD1", "ZeDRJu1", "ZeDRJ:_tu19881", "98asfhj", "adasd", "()=H)d"}; | |
public static Random r = new Random(); | |
public static List<BCrypt.Verifyer> verifyers = new ArrayList<>(); | |
public static boolean introduceMemoryLeak = false; | |
public static void main(String[] args) { | |
boolean last = false; | |
for (int i = 0; i < 10000; i++) { | |
long start = System.nanoTime(); | |
BCrypt.Verifyer v = BCrypt.verifyer(); | |
BCrypt.Result verify = v.verify(pws[r.nextInt(pws.length)].toCharArray(), "$2a$06$999999999999999999999u6RB0P9UmbdbQgjoQFEJsrvrKe.BoU6q".toCharArray()); | |
last = verify.verified; | |
if (introduceMemoryLeak) { | |
verifyers.add(v); | |
} | |
System.out.println(String.format("took %2d", System.nanoTime() - start)); | |
} | |
System.out.println("done! " + last); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
After 100 iterations:
After 10_000 iterations:
After 100_000 iterations:
Additionally I looked at execution time and on my machine it is steady at around 3.5ms per loop after 100_000 iterations
It currently does not look like memory scales with the execution count, wich would make a memory leak highly unlikely.