Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Keeping track of temporary files created by GdipPrivateAddMemoryFont #691

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 42 additions & 1 deletion src/font.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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;
}
Expand Down Expand Up @@ -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);
}

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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;
}
Expand Down
7 changes: 7 additions & 0 deletions src/fontcollection-private.h
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down