sp_head has its own member MEM_ROOT main_mem_root.
The caller of sp_head::init_sp_name() currently makes sure to set THD::mem_root to &sphead::main_mem_root, by calling sphead::reset_thd_mem_root(THD*). So the name is effectively created on main_mem_root anyway.
There is no a need to pass a pointer to THD to init_sp_name(). It's much safer to create the name by allocating memory directly on sp_head::main_mem_root, instead of using its alias THD::mem_root.
Under terms of this task we'll do the following:
After this change, the code will be more flexible, as it will be possible to call init_sp_name() without prior call for sp->reset_thd_mem_root(thd).