Some bug fixes to make code compile

palloc/pfree are not authorized in critical sections.