bugfix, malloc/free - enter/leave critical sections