From 62565b42f61f26fd502005658ed1fddf9425a4b4 Mon Sep 17 00:00:00 2001 From: Christophe CURIS Date: Sun, 10 Nov 2013 17:41:06 +0100 Subject: [PATCH] WINGs: Do not allocate memory for a fixed-size short-lived buffer Allocating memory with 'malloc' has a cost and participate to memory fragmentation, so for a temporary buffer that has a fixed size let's prefer allocating it on the stack. Signed-off-by: Christophe CURIS --- WINGs/wfilepanel.c | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/WINGs/wfilepanel.c b/WINGs/wfilepanel.c index 6785beb9..10eea336 100644 --- a/WINGs/wfilepanel.c +++ b/WINGs/wfilepanel.c @@ -693,32 +693,35 @@ static void normalizePath(char *s) static void deleteFile(WMWidget *widget, void *p_panel) { WMFilePanel *panel = p_panel; - char *file, *buffer; + char *file; + char buffer[512]; struct stat filestat; WMScreen *scr = WMWidgetScreen(panel->win); -#define __msgbufsize__ 512 /* Parameter not used, but tell the compiler that it is ok */ (void) widget; - buffer = wmalloc(__msgbufsize__); file = getCurrentFileName(panel); normalizePath(file); if (stat(file, &filestat) == -1) { - snprintf(buffer, __msgbufsize__, _("Can not find %s: %s"), file, strerror(errno)); + snprintf(buffer, sizeof(buffer), + _("Can not find %s: %s"), + file, strerror(errno)); showError(scr, panel->win, buffer, NULL); goto out; } - snprintf(buffer, __msgbufsize__, _("Delete %s %s?"), + snprintf(buffer, sizeof(buffer), _("Delete %s %s?"), S_ISDIR(filestat.st_mode) ? _("directory") : _("file"), file); if (!WMRunAlertPanel(WMWidgetScreen(panel->win), panel->win, _("Warning"), buffer, _("OK"), _("Cancel"), NULL)) { if (remove(file) == -1) { - snprintf(buffer, __msgbufsize__, _("Removing %s failed: %s"), file, strerror(errno)); + snprintf(buffer, sizeof(buffer), + _("Removing %s failed: %s"), + file, strerror(errno)); showError(scr, panel->win, buffer, NULL); } else { char *s = strrchr(file, '/'); @@ -729,11 +732,8 @@ static void deleteFile(WMWidget *widget, void *p_panel) } out: - if (buffer) - wfree(buffer); if (file) wfree(file); -#undef __msgbufsize__ } static void goUnmount(WMWidget *widget, void *p_panel) -- 2.11.4.GIT