- if (--item->count <= 0) {
- // remove from the cache
- XFreeGC(**display, _gc);
- _cache[_screen][color] = 0;
- delete item;
+ if (_created) {
+ CacheItem *item = _cache[_screen][color];
+ assert(item); // better be...
+
+ if (--item->count <= 0) {
+ // remove from the cache
+ XFreeGC(**display, _gc);
+ _cache[_screen][color] = 0;
+ delete item;
+
+ if (_allocated) {
+ const ScreenInfo *info = display->screenInfo(_screen);
+ XFreeColors(**display, info->colormap(), &_pixel, 1, 0);
+ }
+ }