+ for (node = m_palettes.First(); node; node = next) {
+ wxXPalette *c = (wxXPalette *)node->Data();
+ unsigned long *pix_array = c->m_pix_array;
+ Colormap cmap = (Colormap) c->m_cmap;
+ bool destroyable = c->m_destroyable;
+ int pix_array_n = c->m_pix_array_n;
+ display = (Display*) c->m_display;
+
+ if (pix_array_n > 0)
+ {
+ // XFreeColors(display, cmap, pix_array, pix_array_n, 0);
+ // Be careful not to free '0' pixels...
+ int i, j;
+ for(i=j=0; i<pix_array_n; i=j) {
+ while(j<pix_array_n && pix_array[j]!=0) j++;
+ if(j > i) XFreeColors(display, cmap, &pix_array[i], j-i, 0);
+ while(j<pix_array_n && pix_array[j]==0) j++;
+ }
+ delete [] pix_array;
+ }
+
+ if (destroyable)
+ XFreeColormap(display, cmap);
+
+ next = node->Next();
+ m_palettes.DeleteNode(node);
+ delete c;
+ }