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

Fix various crashes, leaks, and cycles #468

Closed
wants to merge 6 commits into from

Avoid leaking FcPattern pointers.

  • Loading branch information
jdm committed May 22, 2013
commit c8b10ec6b8417f363edbaade8e15a55ccfdef89d
@@ -6,7 +6,7 @@ extern mod freetype;
extern mod fontconfig;

use fontconfig::fontconfig::{
FcChar8, FcResultMatch, FcSetSystem,
FcChar8, FcResultMatch, FcSetSystem, FcPattern,
FcResultNoMatch, FcMatchPattern, FC_SLANT_ITALIC, FC_WEIGHT_BOLD
};
use fontconfig::fontconfig::bindgen::{
@@ -127,10 +127,21 @@ pub impl FontListHandle {
}
}

struct AutoPattern {
pattern: *FcPattern
}

impl Drop for AutoPattern {
fn finalize(&self) {
FcPatternDestroy(self.pattern);
}
}

pub fn path_from_identifier(name: ~str, style: &UsedFontStyle) -> Result<~str, ()> {
unsafe {
let config = FcConfigGetCurrent();
let pattern = FcPatternCreate();
let wrapper = AutoPattern { pattern: FcPatternCreate() };
let pattern = wrapper.pattern;
let res = do str::as_c_str("family") |FC_FAMILY| {
do str::as_c_str(name) |family| {
FcPatternAddString(pattern, FC_FAMILY, family as *FcChar8)
@@ -166,7 +177,8 @@ pub fn path_from_identifier(name: ~str, style: &UsedFontStyle) -> Result<~str, (
}
FcDefaultSubstitute(pattern);
let result = FcResultNoMatch;
let result_pattern = FcFontMatch(config, pattern, &result);
let result_wrapper = AutoPattern { pattern: FcFontMatch(config, pattern, &result) };
let result_pattern = result_wrapper.pattern;
if result != FcResultMatch && result_pattern.is_null() {
debug!("obtaining match to pattern failed");
return Err(());
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.