mirror of
https://github.com/ClassiCube/ClassiCube.git
synced 2025-09-17 11:35:08 -04:00
Fix fonts leaking file handles
This commit is contained in:
parent
f6e3478eed
commit
1b8210c7ca
@ -884,6 +884,29 @@ static unsigned long FontData_Read(FT_Stream s, unsigned long offset, unsigned c
|
||||
return res ? 0 : count;
|
||||
}
|
||||
|
||||
static void FontData_Free(struct FontData* font) {
|
||||
int i;
|
||||
|
||||
/* Close the actual underlying file */
|
||||
struct Stream* source = &font->file;
|
||||
if (!source->Meta.File) return;
|
||||
source->Close(source);
|
||||
|
||||
for (i = 0; i < 256; i++) {
|
||||
if (!font->glyphs[i]) continue;
|
||||
FT_Done_Glyph(font->glyphs[i]);
|
||||
}
|
||||
for (i = 0; i < 256; i++) {
|
||||
if (!font->shadow_glyphs[i]) continue;
|
||||
FT_Done_Glyph(font->shadow_glyphs[i]);
|
||||
}
|
||||
}
|
||||
|
||||
static void FontData_Close(FT_Stream stream) {
|
||||
struct FontData* data = stream->descriptor.pointer;
|
||||
FontData_Free(data);
|
||||
}
|
||||
|
||||
static bool FontData_Init(const String* path, struct FontData* data, FT_Open_Args* args) {
|
||||
FileHandle file;
|
||||
uint32_t size;
|
||||
@ -897,7 +920,7 @@ static bool FontData_Init(const String* path, struct FontData* data, FT_Open_Arg
|
||||
|
||||
data->stream.descriptor.pointer = data;
|
||||
data->stream.read = FontData_Read;
|
||||
data->stream.close = NULL;
|
||||
data->stream.close = FontData_Close;
|
||||
|
||||
data->stream.memory = &ft_mem;
|
||||
data->stream.cursor = NULL;
|
||||
@ -923,22 +946,6 @@ static bool FontData_Init(const String* path, struct FontData* data, FT_Open_Arg
|
||||
return true;
|
||||
}
|
||||
|
||||
static void FontData_Free(struct FontData* font) {
|
||||
int i;
|
||||
/* Close the actual file stream */
|
||||
struct Stream* source = &font->file;
|
||||
source->Close(source);
|
||||
|
||||
for (i = 0; i < 256; i++) {
|
||||
if (!font->glyphs[i]) continue;
|
||||
FT_Done_Glyph(font->glyphs[i]);
|
||||
}
|
||||
for (i = 0; i < 256; i++) {
|
||||
if (!font->shadow_glyphs[i]) continue;
|
||||
FT_Done_Glyph(font->shadow_glyphs[i]);
|
||||
}
|
||||
}
|
||||
|
||||
void Font_GetNames(StringsBuffer* buffer) {
|
||||
String entry, name, path;
|
||||
int i;
|
||||
@ -1067,7 +1074,6 @@ static int Font_Register(const String* path, int faceIndex) {
|
||||
}
|
||||
|
||||
FT_Done_Face(data.face);
|
||||
FontData_Free(&data);
|
||||
return count;
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user