No reason allocating this so early. Allocate when processing the ```mask``` argument. Also, though PostgreSQL memory contexts automatically clean up after themselves, that's not guaranteed. Hence, clean up after yourself. Or add ```mask``` to ```arg``` and add the appropriate initialization/destruction statements.