Created
August 1, 2012 19:00
-
-
Save nonsequitur/3229809 to your computer and use it in GitHub Desktop.
HarfBuzz Memory Leak
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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