diff --git a/src/font.c b/src/font.c index 53fc58cf8..173a40ee8 100644 --- a/src/font.c +++ b/src/font.c @@ -162,6 +162,36 @@ GdipNewInstalledFontCollection (GpFontCollection **fontCollection) return Ok; } +void free_tempfiles_list(StringList* head) +{ + while (head) + { + remove (head->str); + head->str = NULL; + head = head->next; + } +} + +void destroy_string_list(StringList* head) +{ + while (head) + { + StringList* next = head->next; + GdipFree (head); + head = next; + } +} + +GpStatus push_front_string_list(StringList** head, char* str) +{ + StringList* newHead = GdipAlloc (sizeof(StringList)); + if (!newHead) return OutOfMemory; + newHead->str = str; + newHead->next = *head; + *head = newHead; + return Ok; +} + // coverity[+alloc : arg-*0] GpStatus WINGDIPAPI GdipNewPrivateFontCollection (GpFontCollection **fontCollection) @@ -186,6 +216,8 @@ GdipNewPrivateFontCollection (GpFontCollection **fontCollection) pango_fc_font_map_set_config ((PangoFcFontMap *)result->pango_font_map, result->config); #endif + result->tempfiles = NULL; + *fontCollection = result; return Ok; } @@ -215,6 +247,11 @@ GdipDeletePrivateFontCollection (GpFontCollection **fontCollection) FcConfigDestroy ((*fontCollection)->config); (*fontCollection)->config = NULL; } + if ((*fontCollection)->tempfiles != NULL) { + free_tempfiles_list ((*fontCollection)->tempfiles); + destroy_string_list ((*fontCollection)->tempfiles); + (*fontCollection)->tempfiles = NULL; + } GdipFree (*fontCollection); } @@ -1399,7 +1436,8 @@ GdipCreateFontFromLogfontW(HDC hdc, GDIPCONST LOGFONTW *logfont, GpFont **font) GpStatus WINGDIPAPI GdipPrivateAddMemoryFont(GpFontCollection *fontCollection, GDIPCONST void *memory, INT length) { - FcChar8 fontfile[256]; + FcChar8* fontfile = (FcChar8*)GdipAlloc (256); + if (!fontfile) return OutOfMemory; #ifdef WIN32 FILE *f; #else @@ -1440,6 +1478,9 @@ GdipPrivateAddMemoryFont(GpFontCollection *fontCollection, GDIPCONST void *memor /* FIXME - May we delete our temporary font file or does FcConfigAppFontAddFile just reference our file? */ /* unlink(fontfile); */ + /* We cannot delete our temporary font file, we must keep + them and manually delete them later */ + if (push_front_string_list (&(fontCollection->tempfiles), fontfile)) return OutOfMemory; return Ok; } diff --git a/src/fontcollection-private.h b/src/fontcollection-private.h index 96e2a599f..e136f1736 100644 --- a/src/fontcollection-private.h +++ b/src/fontcollection-private.h @@ -37,12 +37,19 @@ #include "gdiplus-private.h" +struct _StringList { + char* str; + struct _StringList* next; +}; +typedef struct _StringList StringList; + struct _FontCollection { FcFontSet* fontset; FcConfig* config; /* Only for private collections */ #ifdef USE_PANGO_RENDERING PangoFontMap* pango_font_map; #endif + StringList* tempfiles; }; #include "fontcollection.h"