Fix memory limiter and extend its tests.