This fix is not correct. No system function calls (well basically most of them) or even more no PostgreSQL-specific calls should happen while holding a spinlock. elog() is a good example of what not to do. One example: imagine a palloc failure while holding this spinlock in this elog().