1
0
mirror of https://github.com/gryf/wmaker.git synced 2025-12-24 15:12:32 +01:00

SwitchPanel: make sure WMRetainColor and WMReleaseColor calls are even

The number of calls to WMRetainColor for a color in use should the same as the number of calls to WMReleaseColor
to free that color. In case of discrepancy, random crashes can happen and memory is not freed properly.
To debug that issue I checked the retained colors when the switchpanel is opened and then checked if those colors are properly released once the panel is closed.

This patch fixes the issue mentioned at https://github.com/window-maker/wmaker/issues/22
This commit is contained in:
David Maciejak
2023-02-10 19:00:00 +08:00
committed by Carlos R. Mafra
parent 04e9f33437
commit 2a14004fc3
3 changed files with 13 additions and 7 deletions

View File

@@ -61,6 +61,7 @@ struct SwitchPanel {
WMFont *font;
WMColor *white;
WMColor *gray;
};
/* these values will be updated whenever the switch panel
@@ -154,11 +155,9 @@ static void changeImage(WSwitchPanel *panel, int idecks, int selected, Bool dim,
border_space + pos.y, back->width, back->height, 0, 0);
} else {
RColor color;
WMScreen *wscr = WMWidgetScreen(icon);
color.red = 255;
color.red = WMRedComponentOfColor(WMGrayColor(wscr)) >> 8;
color.green = WMGreenComponentOfColor(WMGrayColor(wscr)) >> 8;
color.blue = WMBlueComponentOfColor(WMGrayColor(wscr)) >> 8;
color.red = WMRedComponentOfColor(panel->gray) >> 8;
color.green = WMGreenComponentOfColor(panel->gray) >> 8;
color.blue = WMBlueComponentOfColor(panel->gray) >> 8;
RFillImage(back, &color);
}
@@ -454,6 +453,7 @@ WSwitchPanel *wInitSwitchPanel(WScreen *scr, WWindow *curwin, Bool class_only)
}
panel->white = WMWhiteColor(scr->wmscreen);
panel->gray = WMGrayColor(scr->wmscreen);
panel->font = WMBoldSystemFontOfSize(scr->wmscreen, WMScaleY(12));
panel->icons = WMCreateArray(count);
panel->images = WMCreateArray(count);
@@ -589,6 +589,9 @@ void wSwitchPanelDestroy(WSwitchPanel *panel)
if (panel->white)
WMReleaseColor(panel->white);
if (panel->gray)
WMReleaseColor(panel->gray);
wfree(panel);
}