I have another little idea that fits well here: repalloc0 and repalloc0_array. These zero out the space added by repalloc. This is a common pattern in the backend code that is quite hairy to code by hand. See attached patch.
pgsql-hackers by date:
Соглашаюсь с условиями обработки персональных данных