diff --git a/src/parsing/font.c b/src/parsing/font.c index 1b2dd43..3850dbc 100644 --- a/src/parsing/font.c +++ b/src/parsing/font.c @@ -140,6 +140,7 @@ void parse_font(const char *buf, size_t buf_len, document_t *doc) { if (ft_lib == NULL) { FT_Init_FreeType(&ft_lib); } + if (buf == NULL) { return; } @@ -169,6 +170,7 @@ void parse_font(const char *buf, size_t buf_len, document_t *doc) { APPEND_META(doc, meta_name) if (ScanCtx.tn_size <= 0) { + FT_Done_Face(face); return; } @@ -178,6 +180,7 @@ void parse_font(const char *buf, size_t buf_len, document_t *doc) { err = FT_Set_Pixel_Sizes(face, 0, pixel); if (err != 0) { LOG_WARNINGF(doc->filepath, "(font.c) FT_Set_Pixel_Sizes() returned error code [%d] %s", err, ft_error_string(err)) + FT_Done_Face(face); return; } @@ -224,3 +227,7 @@ void parse_font(const char *buf, size_t buf_len, document_t *doc) { FT_Done_Face(face); } + +void cleanup_font() { + FT_Done_FreeType(ft_lib); +} diff --git a/src/parsing/font.h b/src/parsing/font.h index 9d1d736..a648e94 100644 --- a/src/parsing/font.h +++ b/src/parsing/font.h @@ -5,5 +5,6 @@ void parse_font(const char * buf, size_t buf_len, document_t *doc); +void cleanup_font(); #endif