mirror of
https://github.com/servo/servo.git
synced 2025-06-25 09:34:32 +01:00
Avoid leaking FcPattern pointers.
This commit is contained in:
parent
a43f92a300
commit
c8b10ec6b8
1 changed files with 15 additions and 3 deletions
|
@ -6,7 +6,7 @@ extern mod freetype;
|
||||||
extern mod fontconfig;
|
extern mod fontconfig;
|
||||||
|
|
||||||
use fontconfig::fontconfig::{
|
use fontconfig::fontconfig::{
|
||||||
FcChar8, FcResultMatch, FcSetSystem,
|
FcChar8, FcResultMatch, FcSetSystem, FcPattern,
|
||||||
FcResultNoMatch, FcMatchPattern, FC_SLANT_ITALIC, FC_WEIGHT_BOLD
|
FcResultNoMatch, FcMatchPattern, FC_SLANT_ITALIC, FC_WEIGHT_BOLD
|
||||||
};
|
};
|
||||||
use fontconfig::fontconfig::bindgen::{
|
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, ()> {
|
pub fn path_from_identifier(name: ~str, style: &UsedFontStyle) -> Result<~str, ()> {
|
||||||
unsafe {
|
unsafe {
|
||||||
let config = FcConfigGetCurrent();
|
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| {
|
let res = do str::as_c_str("family") |FC_FAMILY| {
|
||||||
do str::as_c_str(name) |family| {
|
do str::as_c_str(name) |family| {
|
||||||
FcPatternAddString(pattern, FC_FAMILY, family as *FcChar8)
|
FcPatternAddString(pattern, FC_FAMILY, family as *FcChar8)
|
||||||
|
@ -166,7 +177,8 @@ pub fn path_from_identifier(name: ~str, style: &UsedFontStyle) -> Result<~str, (
|
||||||
}
|
}
|
||||||
FcDefaultSubstitute(pattern);
|
FcDefaultSubstitute(pattern);
|
||||||
let result = FcResultNoMatch;
|
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() {
|
if result != FcResultMatch && result_pattern.is_null() {
|
||||||
debug!("obtaining match to pattern failed");
|
debug!("obtaining match to pattern failed");
|
||||||
return Err(());
|
return Err(());
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue