Skip to content

Commit

Permalink
Don't cross allocators/deallocators
Browse files Browse the repository at this point in the history
  • Loading branch information
CraftSpider committed Apr 16, 2024
1 parent 516a0da commit f8dacb6
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 7 deletions.
13 changes: 10 additions & 3 deletions crates/engine_xetex/xetex/xetex-ext.c
Original file line number Diff line number Diff line change
Expand Up @@ -659,11 +659,18 @@ loadOTfont(RawPlatformFontRef fontRef, XeTeXFont font, Fixed scaled_size, char*
engine = createLayoutEngine(font, script, language,
features, nFeatures, shapers, rgbValue, extend, slant, embolden);

if (!engine) {
// only free these if creation failed, otherwise the engine now owns them
// The layout engine clones all these - this is temporary to avoid using
// different alloc/dealloc
if (features) {
free(features);
}
if (shapers) {
free(shapers);
} else {
}
if (language) {
free(language);

Check warning on line 671 in crates/engine_xetex/xetex/xetex-ext.c

View check run for this annotation

Codecov / codecov/patch

crates/engine_xetex/xetex/xetex-ext.c#L671

Added line #L671 was not covered by tests
}
if (engine) {
native_font_type_flag = OTGR_FONT_FLAG;
}

Expand Down
9 changes: 5 additions & 4 deletions crates/xetex_layout/src/c_api/engine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -107,12 +107,13 @@ impl XeTeXLayoutEngineBase {
let font = Box::from_raw(font);

let language = if !language.is_null() {
Some(Cow::Owned(CString::from_raw(language)))
Some(Cow::Owned(CStr::from_ptr(language).to_owned()))

Check warning on line 110 in crates/xetex_layout/src/c_api/engine.rs

View check run for this annotation

Codecov / codecov/patch

crates/xetex_layout/src/c_api/engine.rs#L110

Added line #L110 was not covered by tests
} else {
None
};
let features = if !features.is_null() {
Box::from_raw(ptr::slice_from_raw_parts_mut(features, n_features as usize))
let features: Box<[_]> = if !features.is_null() {
let len = n_features as usize;
Box::from(slice::from_raw_parts(features, len))
} else {
Box::new([])
};
Expand All @@ -122,7 +123,7 @@ impl XeTeXLayoutEngineBase {
len += 1;
}
len += 1;
Vec::from_raw_parts(shapers, len, len)
slice::from_raw_parts(shapers, len).to_vec()
} else {
Vec::new()
};
Expand Down

0 comments on commit f8dacb6

Please sign in to comment.