Skip to content
This repository was archived by the owner on Mar 7, 2025. It is now read-only.
This repository was archived by the owner on Mar 7, 2025. It is now read-only.

GdipPrivateAddMemoryFont does not clean up temporary files #690

@trungnt2910

Description

@trungnt2910

Trying to use a C# application that calls System.PrivateFontCollection.AddMemoryFont on Linux leaves a bunch of unused font files in the tmp folder, even after calling Dispose.

Most functions in Mono's PrivateFontCollection are simply wrappers to libgdiplus calls, so I guess the bug originates from here.

Digging through the source code, it seems that this piece of code here is responsible:

#ifdef WIN32
	f = CreateTempFile (fontfile);
	if (!f)
		return FileNotFound;

	if (fwrite(memory, sizeof(BYTE), length, f) != length) {
		fclose (f);
		return FileNotFound;
	}

	fclose (f);
#else
	strcpy ((char *) fontfile, "/tmp/ffXXXXXX");
	f = mkstemp ((char *) fontfile);
	
	if (f == -1)
		return FileNotFound;

	if (write (f, memory, length) != length) {
		close (f);
		return FileNotFound;
	}
	close (f);
#endif

	FcConfigAppFontAddFile (fontCollection->config, fontfile);
	/* FIXME - May we delete our temporary font file or does 
	   FcConfigAppFontAddFile just reference our file?  */
	/* unlink(fontfile); */

	return Ok;

After research, at least on my Ubuntu 20.04 machine, FcConfigAppFontAddFile simply references that file, deleting the font makes the app crash when a new Form or Control is drawn. However, the function does not seem to save the temp files anywhere.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions