Wrapper for create_function, avoiding memory leaks