Skip to content

Commit f8dacb6

Browse files
committed
Don't cross allocators/deallocators
1 parent 516a0da commit f8dacb6

File tree

2 files changed

+15
-7
lines changed

2 files changed

+15
-7
lines changed

crates/engine_xetex/xetex/xetex-ext.c

+10-3
Original file line numberDiff line numberDiff line change
@@ -659,11 +659,18 @@ loadOTfont(RawPlatformFontRef fontRef, XeTeXFont font, Fixed scaled_size, char*
659659
engine = createLayoutEngine(font, script, language,
660660
features, nFeatures, shapers, rgbValue, extend, slant, embolden);
661661

662-
if (!engine) {
663-
// only free these if creation failed, otherwise the engine now owns them
662+
// The layout engine clones all these - this is temporary to avoid using
663+
// different alloc/dealloc
664+
if (features) {
664665
free(features);
666+
}
667+
if (shapers) {
665668
free(shapers);
666-
} else {
669+
}
670+
if (language) {
671+
free(language);
672+
}
673+
if (engine) {
667674
native_font_type_flag = OTGR_FONT_FLAG;
668675
}
669676

crates/xetex_layout/src/c_api/engine.rs

+5-4
Original file line numberDiff line numberDiff line change
@@ -107,12 +107,13 @@ impl XeTeXLayoutEngineBase {
107107
let font = Box::from_raw(font);
108108

109109
let language = if !language.is_null() {
110-
Some(Cow::Owned(CString::from_raw(language)))
110+
Some(Cow::Owned(CStr::from_ptr(language).to_owned()))
111111
} else {
112112
None
113113
};
114-
let features = if !features.is_null() {
115-
Box::from_raw(ptr::slice_from_raw_parts_mut(features, n_features as usize))
114+
let features: Box<[_]> = if !features.is_null() {
115+
let len = n_features as usize;
116+
Box::from(slice::from_raw_parts(features, len))
116117
} else {
117118
Box::new([])
118119
};
@@ -122,7 +123,7 @@ impl XeTeXLayoutEngineBase {
122123
len += 1;
123124
}
124125
len += 1;
125-
Vec::from_raw_parts(shapers, len, len)
126+
slice::from_raw_parts(shapers, len).to_vec()
126127
} else {
127128
Vec::new()
128129
};

0 commit comments

Comments
 (0)