Added stack check in replace(). Also fixed a leak that could occur if it runs out of memory. Rev: src/builtin_functions.c:1.545