[3.5.x] Use a dynamically allocated buffer to remove size restriction on templat...

...e files
It looks like you can just calloc the buffer, and only one free needed at the end.