Skip to content

Commit

Permalink
Plug a memory leak when adding a font on some platforms
Browse files Browse the repository at this point in the history
On macOS (with Core Text) and some versions of Windows (with DirectWrite)
(specifically, Windows 10+ Win32 as well as all versions of WinRT/UWP),
we read font metadata on our own via FreeType, filling implicit_meta in
ass_font_provider_add_font. However, we forgot to free it upon successful
font registration, leaking the memory allocated for the font name strings.

The list of affected platforms would likely have expanded in the future,
as we eventually intend to read font names on our own across the board.

Leak introduced in commit 887e6cc.

As a quick fix, add the corresponding frees on the successful path.
Ideally, we should refactor this function to avoid copying any freshly
allocated memory to begin with (and thus to avoid the need to free it).

Fixes: libass#699
  • Loading branch information
astiob committed Jul 27, 2023
1 parent d1f0f20 commit 91422bd
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions libass/ass_fontselect.c
Original file line number Diff line number Diff line change
Expand Up @@ -534,6 +534,10 @@ ass_font_provider_add_font(ASS_FontProvider *provider,
info->provider = provider;

selector->n_font++;

free_font_info(&implicit_meta);
free(implicit_meta.postscript_name);

return true;

error:
Expand Down

0 comments on commit 91422bd

Please sign in to comment.