From adb601eaa9844cecbcd22d1ff6090be5dd645789 Mon Sep 17 00:00:00 2001 From: Stu Black Date: Thu, 2 Oct 2025 13:26:57 -0400 Subject: [PATCH] Use free() on memory returned by FcNameUnparse and hand back wfree-managed pointers from our functions. This is necessary because we now allocate memory through a special allocator of our own on the Rust side. Passing raw malloc'd pointers to wfree will break things. --- WINGs/wfont.c | 12 +++++++++--- WPrefs.app/FontSimple.c | 6 +++++- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/WINGs/wfont.c b/WINGs/wfont.c index 999aaa44..52af4bfc 100644 --- a/WINGs/wfont.c +++ b/WINGs/wfont.c @@ -51,12 +51,15 @@ static char *xlfdToFcName(const char *xlfd) { FcPattern *pattern; char *fname; + char *result; pattern = xlfdToFcPattern(xlfd); fname = (char *)FcNameUnparse(pattern); + result = wstrdup(fname); + free(fname); FcPatternDestroy(pattern); - return fname; + return result; } static Bool hasProperty(FcPattern * pattern, const char *property) @@ -92,6 +95,7 @@ static Bool hasPropertyWithStringValue(FcPattern * pattern, const char *object, static char *makeFontOfSize(const char *font, int size, const char *fallback) { FcPattern *pattern; + char *name; char *result; if (font[0] == '-') { @@ -115,7 +119,9 @@ static char *makeFontOfSize(const char *font, int size, const char *fallback) /*FcPatternPrint(pattern); */ - result = (char *)FcNameUnparse(pattern); + name = (char *)FcNameUnparse(pattern); + result = wstrdup(name); + free(name); FcPatternDestroy(pattern); return result; @@ -421,7 +427,7 @@ WMFont *WMCopyFontWithStyle(WMScreen * scrPtr, WMFont * font, WMFontStyle style) name = (char *)FcNameUnparse(pattern); copy = WMCreateFont(scrPtr, name); FcPatternDestroy(pattern); - wfree(name); + free(name); return copy; } diff --git a/WPrefs.app/FontSimple.c b/WPrefs.app/FontSimple.c index 2147b985..13f01edb 100644 --- a/WPrefs.app/FontSimple.c +++ b/WPrefs.app/FontSimple.c @@ -288,6 +288,7 @@ static char *getSelectedFont(_Panel * panel, FcChar8 * curfont) WMListItem *item; FcPattern *pat; char *name; + char *result; if (curfont) pat = FcNameParse(curfont); @@ -321,9 +322,12 @@ static char *getSelectedFont(_Panel * panel, FcChar8 * curfont) } name = (char *)FcNameUnparse(pat); + result = wstrdup(name); + free(name); FcPatternDestroy(pat); - return name; + + return result; } static void updateSampleFont(_Panel * panel)