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

GdipPrivateAddMemoryFont does not clean up temporary files #690

Open
trungnt2910 opened this issue Feb 7, 2021 · 0 comments · May be fixed by #691
Open

GdipPrivateAddMemoryFont does not clean up temporary files #690

trungnt2910 opened this issue Feb 7, 2021 · 0 comments · May be fixed by #691

Comments

@trungnt2910
Copy link

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant