aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/xfaces.c38
1 files changed, 24 insertions, 14 deletions
diff --git a/src/xfaces.c b/src/xfaces.c
index 829fb6e7eda..89b8e4c7b5f 100644
--- a/src/xfaces.c
+++ b/src/xfaces.c
@@ -548,20 +548,30 @@ x_free_colors (f, pixels, npixels)
548 if (class != StaticColor && class != StaticGray && class != TrueColor) 548 if (class != StaticColor && class != StaticGray && class != TrueColor)
549 { 549 {
550 Display *dpy = FRAME_X_DISPLAY (f); 550 Display *dpy = FRAME_X_DISPLAY (f);
551 Colormap cmap = DefaultColormapOfScreen (FRAME_X_SCREEN (f)); 551 Colormap cmap = FRAME_X_COLORMAP (f);
552 int screen_no = XScreenNumberOfScreen (FRAME_X_SCREEN (f)); 552 Screen *screen = FRAME_X_SCREEN (f);
553 unsigned long black = BlackPixel (dpy, screen_no); 553 int default_cmap_p = cmap == DefaultColormapOfScreen (screen);
554 unsigned long white = WhitePixel (dpy, screen_no); 554
555 unsigned long *px; 555 if (default_cmap_p)
556 int i, j; 556 {
557 557 /* Be paranoid. If using the default color map, don't ever
558 px = (unsigned long *) alloca (npixels * sizeof *px); 558 try to free the default black and white colors. */
559 for (i = j = 0; i < npixels; ++i) 559 int screen_no = XScreenNumberOfScreen (screen);
560 if (pixels[i] != black && pixels[i] != white) 560 unsigned long black = BlackPixel (dpy, screen_no);
561 px[j++] = pixels[i]; 561 unsigned long white = WhitePixel (dpy, screen_no);
562 562 unsigned long *px;
563 if (j) 563 int i, j;
564 XFreeColors (dpy, cmap, px, j, 0); 564
565 px = (unsigned long *) alloca (npixels * sizeof *px);
566 for (i = j = 0; i < npixels; ++i)
567 if (pixels[i] != black && pixels[i] != white)
568 px[j++] = pixels[i];
569
570 if (j)
571 XFreeColors (dpy, cmap, px, j, 0);
572 }
573 else
574 XFreeColors (dpy, cmap, pixels, npixels, 0);
565 } 575 }
566} 576}
567 577