From 2d2dd9febe1612e5be05dc89dc41271fdba76214 Mon Sep 17 00:00:00 2001 From: Stu Black Date: Thu, 23 Oct 2025 12:24:24 -0400 Subject: [PATCH] Chasing memory bugs: be consistent about wmalloc/wfree. --- src/appmenu.c | 4 ++-- src/misc.c | 12 ++++++------ src/properties.c | 4 ++-- wrlib/tests/testgrad.c | 6 +++--- 4 files changed, 13 insertions(+), 13 deletions(-) diff --git a/src/appmenu.c b/src/appmenu.c index bc708964..11191641 100644 --- a/src/appmenu.c +++ b/src/appmenu.c @@ -139,7 +139,7 @@ static WMenu *parseMenuCommand(WScreen * scr, Window win, char **slist, int coun } wstrlcpy(title, &slist[*index][pos], sizeof(title)); } - data = malloc(sizeof(WAppMenuData)); + data = wmalloc(sizeof(WAppMenuData)); if (data == NULL) { wwarning(_("appmenu: out of memory creating menu for window %lx"), win); wMenuDestroy(menu, True); @@ -152,7 +152,7 @@ static WMenu *parseMenuCommand(WScreen * scr, Window win, char **slist, int coun if (!entry) { wMenuDestroy(menu, True); wwarning(_("appmenu: out of memory creating menu for window %lx"), win); - free(data); + wfree(data); return NULL; } if (rtext[0] != 0) diff --git a/src/misc.c b/src/misc.c index 4cab3584..123def2b 100644 --- a/src/misc.c +++ b/src/misc.c @@ -520,7 +520,7 @@ char *ExpandOptions(WScreen *scr, const char *cmdline) len = strlen(cmdline); olen = len + 1; - out = malloc(olen); + out = wmalloc(olen); if (!out) { wwarning(_("out of memory during expansion of \"%s\""), cmdline); return NULL; @@ -573,7 +573,7 @@ char *ExpandOptions(WScreen *scr, const char *cmdline) (unsigned int)scr->focused_window->client_win); slen = strlen(tmpbuf); olen += slen; - nout = realloc(out, olen); + nout = wrealloc(out, olen); if (!nout) { wwarning(_("out of memory during expansion of '%s' for command \"%s\""), "%w", cmdline); goto error; @@ -590,7 +590,7 @@ char *ExpandOptions(WScreen *scr, const char *cmdline) snprintf(tmpbuf, sizeof(tmpbuf), "0x%x", (unsigned int)scr->current_workspace + 1); slen = strlen(tmpbuf); olen += slen; - nout = realloc(out, olen); + nout = wrealloc(out, olen); if (!nout) { wwarning(_("out of memory during expansion of '%s' for command \"%s\""), "%W", cmdline); goto error; @@ -607,7 +607,7 @@ char *ExpandOptions(WScreen *scr, const char *cmdline) if (user_input) { slen = strlen(user_input); olen += slen; - nout = realloc(out, olen); + nout = wrealloc(out, olen); if (!nout) { wwarning(_("out of memory during expansion of '%s' for command \"%s\""), "%a", cmdline); goto error; @@ -630,7 +630,7 @@ char *ExpandOptions(WScreen *scr, const char *cmdline) } slen = strlen(scr->xdestring); olen += slen; - nout = realloc(out, olen); + nout = wrealloc(out, olen); if (!nout) { wwarning(_("out of memory during expansion of '%s' for command \"%s\""), "%d", cmdline); goto error; @@ -651,7 +651,7 @@ char *ExpandOptions(WScreen *scr, const char *cmdline) } slen = strlen(selection); olen += slen; - nout = realloc(out, olen); + nout = wrealloc(out, olen); if (!nout) { wwarning(_("out of memory during expansion of '%s' for command \"%s\""), "%s", cmdline); goto error; diff --git a/src/properties.c b/src/properties.c index 6751306c..d9ce4249 100644 --- a/src/properties.c +++ b/src/properties.c @@ -133,7 +133,7 @@ int PropGetGNUstepWMAttr(Window window, GNUstepWMAttributes ** attr) if (!data) return False; - *attr = malloc(sizeof(GNUstepWMAttributes)); + *attr = wmalloc(sizeof(GNUstepWMAttributes)); if (!*attr) { XFree(data); return False; @@ -183,7 +183,7 @@ void PropSetIconTileHint(WScreen * scr, RImage * image) imageAtom = XInternAtom(dpy, "_RGBA_IMAGE", False); } - tmp = malloc(image->width * image->height * 4 + 4); + tmp = wmalloc(image->width * image->height * 4 + 4); if (!tmp) { wwarning("could not allocate memory to set _WINDOWMAKER_ICON_TILE hint"); return; diff --git a/wrlib/tests/testgrad.c b/wrlib/tests/testgrad.c index 0b5a7994..4b555aa4 100644 --- a/wrlib/tests/testgrad.c +++ b/wrlib/tests/testgrad.c @@ -38,7 +38,7 @@ int main(int argc, char **argv) else ProgName++; - color_name = (char **)malloc(sizeof(char *) * argc); + color_name = (char **)wmalloc(sizeof(char *) * argc); if (color_name == NULL) { fprintf(stderr, "Cannot allocate memory!\n"); exit(1); @@ -106,13 +106,13 @@ int main(int argc, char **argv) exit(1); } - colors = malloc(sizeof(RColor *) * (ncolors + 1)); + colors = wmalloc(sizeof(RColor *) * (ncolors + 1)); for (i = 0; i < ncolors; i++) { if (!XParseColor(dpy, ctx->cmap, color_name[i], &color)) { printf("could not parse color \"%s\"\n", color_name[i]); exit(1); } else { - colors[i] = malloc(sizeof(RColor)); + colors[i] = wmalloc(sizeof(RColor)); colors[i]->red = color.red >> 8; colors[i]->green = color.green >> 8; colors[i]->blue = color.blue >> 8;