Fix some potential memory leaks within graphics.c