[aml] fix memleak, add queue mutex, cleanup