Created
November 20, 2016 15:08
-
-
Save ebraminio/58820475ee5554a2731ce7985896a216 to your computer and use it in GitHub Desktop.
Minimal code to repro hb_coretext 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
#include <stdlib.h> | |
#include <stdio.h> | |
#include <hb.h> | |
int main(int argc, char **argv) { | |
FILE *f = fopen("/Library/Fonts/Tahoma.ttf", "rb"); | |
fseek(f, 0, SEEK_END); | |
long fsize = ftell(f); | |
fseek(f, 0, SEEK_SET); | |
char* font = (char*)malloc(fsize + 1); | |
fread(font, fsize, 1, f); | |
fclose(f); | |
hb_blob_t *hb_blob = hb_blob_create(font, fsize, HB_MEMORY_MODE_WRITABLE, NULL, 0); | |
const char *shapers[] = { "coretext", 0 }; // not any leak when "ot" used instead | |
for (int i = 0; i < 100; ++i) { | |
hb_face_t *hb_face = hb_face_create(hb_blob, 0); | |
hb_font_t *hb_font = hb_font_create(hb_face); | |
hb_buffer_t *hb_buffer = hb_buffer_create(); | |
hb_buffer_add_utf8(hb_buffer, "text", -1, 0, -1); | |
hb_buffer_guess_segment_properties(hb_buffer); | |
hb_shape_full(hb_font, hb_buffer, NULL, 0, shapers); | |
hb_buffer_destroy(hb_buffer); | |
hb_font_destroy(hb_font); | |
hb_face_destroy(hb_face); | |
} | |
hb_blob_destroy(hb_blob); | |
free(font); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment