From 2913ac0f0980ad95480629b770f3bd631f0d60be Mon Sep 17 00:00:00 2001 From: Christophe CURIS Date: Fri, 22 Feb 2019 17:03:49 +0100 Subject: [PATCH] Do not allocate memory for a temporary buffer This kind of things participates in memory fragmentation, so it is generally a bad practice when an on-stack allocation is enough. Took opportunity to reduce the buffer size, there's no point in overallocating memory (the new size being still way too much). Signed-off-by: Christophe CURIS --- WPrefs.app/Menu.c | 6 +++--- src/appicon.c | 7 ++----- 2 files changed, 5 insertions(+), 8 deletions(-) diff --git a/WPrefs.app/Menu.c b/WPrefs.app/Menu.c index 810a26b6..fc0b7c62 100644 --- a/WPrefs.app/Menu.c +++ b/WPrefs.app/Menu.c @@ -1436,12 +1436,12 @@ static WEditMenu *buildSubmenu(_Panel * panel, WMPropList * pl) WSetEditMenuItemImage(item, panel->markerPix[data->type]); WSetEditMenuItemData(item, data, (WMCallback *) freeItemData); } else { - char *buf = wmalloc(1024); - snprintf(buf, 1024, _("Invalid menu command \"%s\" with label \"%s\" cleared"), + char buf[256]; + + snprintf(buf, sizeof(buf), _("Invalid menu command \"%s\" with label \"%s\" cleared"), WMGetFromPLString(WMGetFromPLArray(pi, 1)), WMGetFromPLString(WMGetFromPLArray(pi, 0))); WMRunAlertPanel(scr, panel->parent, _("Warning"), buf, _("OK"), NULL, NULL); - wfree(buf); } } diff --git a/src/appicon.c b/src/appicon.c index 66110661..42ce96d0 100644 --- a/src/appicon.c +++ b/src/appicon.c @@ -380,11 +380,10 @@ void wAppIconMove(WAppIcon * aicon, int x, int y) static void updateDockNumbers(WScreen *scr) { int length; - char *ws_numbers; + char ws_numbers[20]; WAppIcon *dicon = scr->dock->icon_array[0]; - ws_numbers = wmalloc(20); - snprintf(ws_numbers, 20, "%i [ %i ]", scr->current_workspace + 1, ((scr->current_workspace / 10) + 1)); + snprintf(ws_numbers, sizeof(ws_numbers), "%i [ %i ]", scr->current_workspace + 1, ((scr->current_workspace / 10) + 1)); length = strlen(ws_numbers); XClearArea(dpy, dicon->icon->core->window, 2, 2, 50, WMFontHeight(scr->icon_title_font) + 1, False); @@ -394,8 +393,6 @@ static void updateDockNumbers(WScreen *scr) WMDrawString(scr->wmscreen, dicon->icon->core->window, scr->white, scr->icon_title_font, 3, 2, ws_numbers, length); - - wfree(ws_numbers); } #endif /* WS_INDICATOR */