Skip to content

Instantly share code, notes, and snippets.

@nonsequitur
Created August 1, 2012 19:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nonsequitur/3229809 to your computer and use it in GitHub Desktop.
Save nonsequitur/3229809 to your computer and use it in GitHub Desktop.
HarfBuzz Memory Leak
// g++ -o leak leak.cc -Iharfbuzz/src -Ifreetype/include -lharfbuzz -lfreetype
#include "hb-ft.h"
int main(int argc, char** argv) {
FT_Library library;
FT_Init_FreeType(&library);
FT_Face face;
FT_New_Face(library, "Chunkfive.otf", 0, &face);
FT_Set_Pixel_Sizes(face, 0, 40);
const char text[] = "_";
// Infinite create/destroy loop. Leaks memory.
for (;;) {
hb_font_t* font = hb_ft_font_create(face, 0);
hb_buffer_t* buffer = hb_buffer_create();
hb_buffer_add_utf8(buffer, text, strlen(text), 0, strlen(text));
hb_feature_t feature;
// The leak most probably doesn't depend on the type of the feature.
feature.tag = hb_tag_from_string("kern", 4);
feature.value = 0;
feature.start = 0;
feature.end = (unsigned int) -1;
int num_features = 1;
// With zero features, the leak disappears. (Uncomment the next line.)
// num_features = 0;
hb_shape(font, buffer, &feature, num_features);
hb_buffer_destroy(buffer);
hb_font_destroy(font);
}
FT_Done_Face(face);
FT_Done_FreeType(library);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment