Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Very simple test for probable Memory Leak in Bcrypt Library
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) {
System.out.println(String.format("took %2d", System.nanoTime() - start));
System.out.println("done! " + last);

This comment has been minimized.

Copy link
Owner Author

patrickfav commented Mar 29, 2019

After 100 iterations:

Annotation 2019-03-29 231120_100

After 10_000 iterations:

Annotation 2019-03-29 231120_10000

After 100_000 iterations:

Annotation 2019-03-29 231120_100000

Additionally I looked at execution time and on my machine it is steady at around 3.5ms per loop after 100_000 iterations

took 3401500
took 3410700
took 3449400
took 3422500
took 3425100
took 3412500
took 3418800
took 3425000
took 3432100
done! true

It currently does not look like memory scales with the execution count, wich would make a memory leak highly unlikely.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.