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

Fixing memory leak of shaperList #536

Merged
merged 2 commits into from
Jan 3, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions tectonic/xetex-XeTeXLayoutInterface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ struct XeTeXLayoutEngine_rec
hb_language_t language;
hb_feature_t* features;
char** ShaperList; // the requested shapers
bool shaperListToFree;
char* shaper; // the actually used shaper
int nFeatures;
uint32_t rgbValue;
Expand Down Expand Up @@ -695,6 +696,7 @@ createLayoutEngine(PlatformFontRef fontRef, XeTeXFont font, hb_tag_t script, cha
result->script = script;
result->features = features;
result->ShaperList = shapers;
result->shaperListToFree = false;
result->shaper = NULL;
result->nFeatures = nFeatures;
result->rgbValue = rgbValue;
Expand Down Expand Up @@ -722,6 +724,11 @@ deleteLayoutEngine(XeTeXLayoutEngine engine)
hb_buffer_destroy(engine->hbBuffer);
delete engine->font;
free(engine->shaper);
if(engine->shaperListToFree) {
free(engine->ShaperList);
engine->shaperListToFree = false;
engine->ShaperList = NULL;
}
delete engine;
}

Expand Down Expand Up @@ -785,6 +792,7 @@ layoutChars(XeTeXLayoutEngine engine, uint16_t chars[], int32_t offset, int32_t
engine->ShaperList = (char**) xcalloc(2, sizeof(char*));
engine->ShaperList[0] = (char*) "ot";
engine->ShaperList[1] = NULL;
engine->shaperListToFree = true;
}

shape_plan = hb_shape_plan_create_cached(hbFace, &segment_props, engine->features, engine->nFeatures, engine->ShaperList);
Expand Down
4 changes: 4 additions & 0 deletions tectonic/xetex-xetex0.c
Original file line number Diff line number Diff line change
Expand Up @@ -11135,6 +11135,10 @@ load_native_font(int32_t u, str_number nom, str_number aire, scaled_t s)
/* "measure the width of the space character and set up font parameters" */
p = new_native_character(font_ptr, ' ' );
s = BOX_width(p) + loaded_font_letter_space;
/* Free up the memory */
if(NATIVE_NODE_glyph_info_ptr(p)) {
NATIVE_NODE_glyph_info_ptr(p) = mfree(NATIVE_NODE_glyph_info_ptr(p));
}
free_node(p, NATIVE_NODE_size(p));

font_info[fmem_ptr++].b32.s1 = font_slant;
Expand Down