mirror of
https://github.com/gnif/LookingGlass.git
synced 2024-11-10 08:38:20 +00:00
[client] main: destroy and finish fontconfig usage
Fixes ASAN reported memory leak
This commit is contained in:
parent
30ed563504
commit
f4a925a750
@ -49,6 +49,8 @@ static inline double util_clamp(double x, double min, double max)
|
|||||||
return x;
|
return x;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool util_initUIFonts(void);
|
||||||
|
void util_freeUIFonts(void);
|
||||||
char * util_getUIFont(const char * fontName);
|
char * util_getUIFont(const char * fontName);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -827,8 +827,11 @@ static int lg_run(void)
|
|||||||
g_state.io->BackendFlags |= ImGuiBackendFlags_HasMouseCursors;
|
g_state.io->BackendFlags |= ImGuiBackendFlags_HasMouseCursors;
|
||||||
|
|
||||||
g_state.windowScale = 1.0;
|
g_state.windowScale = 1.0;
|
||||||
g_state.fontName = util_getUIFont(g_params.uiFont);
|
if (util_initUIFonts())
|
||||||
DEBUG_INFO("Using font: %s", g_state.fontName);
|
{
|
||||||
|
g_state.fontName = util_getUIFont(g_params.uiFont);
|
||||||
|
DEBUG_INFO("Using font: %s", g_state.fontName);
|
||||||
|
}
|
||||||
|
|
||||||
app_initOverlays();
|
app_initOverlays();
|
||||||
|
|
||||||
@ -1306,6 +1309,7 @@ int main(int argc, char * argv[])
|
|||||||
|
|
||||||
config_free();
|
config_free();
|
||||||
|
|
||||||
|
util_freeUIFonts();
|
||||||
cleanupCrashHandler();
|
cleanupCrashHandler();
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
@ -31,6 +31,8 @@
|
|||||||
#include <math.h>
|
#include <math.h>
|
||||||
#include <fontconfig/fontconfig.h>
|
#include <fontconfig/fontconfig.h>
|
||||||
|
|
||||||
|
static FcConfig * FontConfig = NULL;
|
||||||
|
|
||||||
bool util_fileGetContents(const char * filename, char ** buffer, size_t * length)
|
bool util_fileGetContents(const char * filename, char ** buffer, size_t * length)
|
||||||
{
|
{
|
||||||
FILE * fh = fopen(filename, "r");
|
FILE * fh = fopen(filename, "r");
|
||||||
@ -259,20 +261,26 @@ int util_mergeOverlappingRects(FrameDamageRect * rects, int count)
|
|||||||
return o;
|
return o;
|
||||||
}
|
}
|
||||||
|
|
||||||
char * util_getUIFont(const char * fontName)
|
bool util_initUIFonts(void)
|
||||||
{
|
{
|
||||||
static FcConfig * fc = NULL;
|
if (FontConfig)
|
||||||
char * ttf = NULL;
|
return true;
|
||||||
|
|
||||||
if (!fc)
|
FontConfig = FcInitLoadConfigAndFonts();
|
||||||
fc = FcInitLoadConfigAndFonts();
|
|
||||||
|
|
||||||
if (!fc)
|
if (!FontConfig)
|
||||||
{
|
{
|
||||||
DEBUG_ERROR("FcInitLoadConfigAndFonts Failed");
|
DEBUG_ERROR("FcInitLoadConfigAndFonts Failed");
|
||||||
return NULL;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
char * util_getUIFont(const char * fontName)
|
||||||
|
{
|
||||||
|
char * ttf = NULL;
|
||||||
|
|
||||||
FcPattern * pat = FcNameParse((const FcChar8*) fontName);
|
FcPattern * pat = FcNameParse((const FcChar8*) fontName);
|
||||||
if (!pat)
|
if (!pat)
|
||||||
{
|
{
|
||||||
@ -280,11 +288,11 @@ char * util_getUIFont(const char * fontName)
|
|||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
FcConfigSubstitute(fc, pat, FcMatchPattern);
|
FcConfigSubstitute(FontConfig, pat, FcMatchPattern);
|
||||||
FcDefaultSubstitute(pat);
|
FcDefaultSubstitute(pat);
|
||||||
FcResult result;
|
FcResult result;
|
||||||
FcChar8 * file = NULL;
|
FcChar8 * file = NULL;
|
||||||
FcPattern * match = FcFontMatch(fc, pat, &result);
|
FcPattern * match = FcFontMatch(FontConfig, pat, &result);
|
||||||
|
|
||||||
if (!match)
|
if (!match)
|
||||||
{
|
{
|
||||||
@ -303,3 +311,13 @@ fail_parse:
|
|||||||
FcPatternDestroy(pat);
|
FcPatternDestroy(pat);
|
||||||
return ttf;
|
return ttf;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void util_freeUIFonts(void)
|
||||||
|
{
|
||||||
|
if (!FontConfig)
|
||||||
|
return;
|
||||||
|
|
||||||
|
FcConfigDestroy(FontConfig);
|
||||||
|
FontConfig = NULL;
|
||||||
|
FcFini();
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user