mapnik/mapnik — pull request #2341 by strk (2014-08-08 09:35:03+00:00)
Title: Fix crash in reading multiface fonts

See https://github.com/mapnik/node-mapnik/issues/289

I'm not sure if this is really a bug with the freetype library, but as you're expected to pass a not-null face object to FT_Open_Face when fetching subsequent faces in a multi-face, I suspect you're not expected to call FT_Done_Face in that case, unless you use FT_Reference_Face.

In any case we're initializing the library as the very first thing in the function and deinitializing it at the end so it is not really worth doing inter-face cleanup so aggressively.

This patch lets the library de-initialization call take care of releasing all faces.
This results in the "close" callback being invoked twice for a 2-faces font, which required protecting against that in the callback.

Valgrind runs clean on the existing font registering testcases + one I added to register the offending fonts.
Non testcase is added by this patch. The wqy-microhei.ttc, GPL licenced, is ~5MB big, so probably not a good candidate for such test. I dunno how to produce a multi-face font right-away to enhance the testsuits.