# HG changeset patch # User Gerd Moellmann # Date 952185529 0 # Node ID 574e0b39816851b1f4ae1bf2789f9335c9607128 # Parent 9094f9408d8dd66e36e7c56404bb24e37d9e89a2 (x_free_colors): Access colormap of frame using FRAME_X_COLORMAP. Be paranoid about freeing black and white when default colormap is used. diff -r 9094f9408d8d -r 574e0b398168 src/xfaces.c --- a/src/xfaces.c Sat Mar 04 14:56:00 2000 +0000 +++ b/src/xfaces.c Sat Mar 04 15:58:49 2000 +0000 @@ -548,20 +548,30 @@ if (class != StaticColor && class != StaticGray && class != TrueColor) { Display *dpy = FRAME_X_DISPLAY (f); - Colormap cmap = DefaultColormapOfScreen (FRAME_X_SCREEN (f)); - int screen_no = XScreenNumberOfScreen (FRAME_X_SCREEN (f)); - unsigned long black = BlackPixel (dpy, screen_no); - unsigned long white = WhitePixel (dpy, screen_no); - unsigned long *px; - int i, j; - - px = (unsigned long *) alloca (npixels * sizeof *px); - for (i = j = 0; i < npixels; ++i) - if (pixels[i] != black && pixels[i] != white) - px[j++] = pixels[i]; - - if (j) - XFreeColors (dpy, cmap, px, j, 0); + Colormap cmap = FRAME_X_COLORMAP (f); + Screen *screen = FRAME_X_SCREEN (f); + int default_cmap_p = cmap == DefaultColormapOfScreen (screen); + + if (default_cmap_p) + { + /* Be paranoid. If using the default color map, don't ever + try to free the default black and white colors. */ + int screen_no = XScreenNumberOfScreen (screen); + unsigned long black = BlackPixel (dpy, screen_no); + unsigned long white = WhitePixel (dpy, screen_no); + unsigned long *px; + int i, j; + + px = (unsigned long *) alloca (npixels * sizeof *px); + for (i = j = 0; i < npixels; ++i) + if (pixels[i] != black && pixels[i] != white) + px[j++] = pixels[i]; + + if (j) + XFreeColors (dpy, cmap, px, j, 0); + } + else + XFreeColors (dpy, cmap, pixels, npixels, 0); } }