Fixed potential memory leak when releasing textures.