module memory malloc updated

fixes a race condition in module_malloc and improves the locking in cmd_command_timeout