severe memory leak caused by broken palette_destroy() function