mirror of
https://github.com/gryf/wmaker.git
synced 2025-12-19 20:38:08 +01:00
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 <christophe.curis@free.fr>
This commit is contained in:
committed by
Carlos R. Mafra
parent
d25631016e
commit
62565b42f6
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user