The output filename is currently free()d before the call to generate_image(), which takes this as a parameter. This patch delays the free until after generate_image returns.