buggins / hibernated

HibernateD is ORM for D language (similar to Hibernate)
82 stars 31 forks source link

Fix memory-leak in SessionFactoryImpl::sessionClosed. #87

Closed vnayar closed 6 months ago

vnayar commented 6 months ago

The std.algorithm.remove() method does not modify in-place an array, which causes 'activeSessions' to accumulate entries and never remove them.

See https://dlang.org/library/std/algorithm/mutation/remove.html

Note that remove does not change the length of the original range directly; instead, it returns the shortened range. If its return value is not assigned to the original range, the original range will retain its original length, though its contents will have changed:

int[] a = [ 3, 5, 7, 8 ]; assert(remove(a, 1) == [ 3, 7, 8 ]); assert(a == [ 3, 7, 8, 8 ]);

SingingBush commented 6 months ago

sorry I forgot to merge this, it seems fine. Would you be able to add a quick unit test though

vnayar commented 6 months ago

sorry I forgot to merge this, it seems fine. Would you be able to add a quick unit test though

I couldn't quite figure out a way of making a true unit-test, due to the explicit dependency on SessionImpl, but I added a small entry to integration-tests instead.