I propose adding the following function to libfontconfig: int FcPatternRefCount(FcPattern const *const p) { if ( !p ) return 0; return p->ref.count; } so that we can destroy an FcPattern as follows: while ( FcPatternRefCount(p) ) FcPatternDestroy(p); Actually just as I'm writing this, I realise that there would be a race condition if two threads are simultaneously calling FcPatternRefCount. So instead maybe just have: int FcPatternDestroyAll(FcPattern*); which would destroy them all.