[vlc-commits] [Git][videolan/vlc][master] 3 commits: freetype: fix incomplete comment
Hugo Beauzée-Luyssen (@chouquette)
gitlab at videolan.org
Fri Jan 7 08:43:32 UTC 2022
Hugo Beauzée-Luyssen pushed to branch master at VideoLAN / VLC
Commits:
65436861 by Lyndon Brown at 2022-01-07T08:26:22+00:00
freetype: fix incomplete comment
"text-layout params" was taken from the comment on `ruby_block_t`, which
presumably properly reflects the purpose (i'm unfamiliar with the context).
- - - - -
f6d4201e by Lyndon Brown at 2022-01-07T08:26:22+00:00
freetype: fix memory leak in certain error paths.
several error paths here failed to release `p_ucs4`.
- - - - -
2437956b by Lyndon Brown at 2022-01-07T08:26:22+00:00
freetype: fix another leak on error
the `i_count` attribute of `p_text_block` tracks the "used" length of three
array attributes, and is only updated at the end of the function, upon
success.
if construction of the `p_rubyblock` object fails and the error path is
taken, the allocated style object `p_mgstyle` will have had its pointer
recorded in the `pp_styles` array, but since under the error path `i_count`
will not have been increased, the code later used to destroy the text block
object will ignore the portion of the realloc'd `pp_styles` array that
recorded that `p_mgstyle` pointer, and thus this object instance will not
be free'd by it creating a leak. furthermore if the function is called
again then the pointer would get overwritten by a new one.
we must thus ensure that we destroy it in the error path.
- - - - -
2 changed files:
- modules/text_renderer/freetype/freetype.c
- modules/text_renderer/freetype/text_layout.h
Changes:
=====================================
modules/text_renderer/freetype/freetype.c
=====================================
@@ -848,6 +848,8 @@ static size_t AddTextAndStyles( filter_sys_t *p_sys,
const text_style_t *p_style,
layout_text_block_t *p_text_block )
{
+ text_style_t *p_mgstyle = NULL;
+
/* Convert chars to unicode */
size_t i_bytes;
uni_char_t *p_ucs4 = ToUCS4( psz_text, &i_bytes );
@@ -857,40 +859,37 @@ static size_t AddTextAndStyles( filter_sys_t *p_sys,
const size_t i_newchars = i_bytes / 4;
const size_t i_new_count = p_text_block->i_count + i_newchars;
if( SIZE_MAX / 4 < i_new_count )
- {
- free( p_ucs4 );
- return 0;
- }
+ goto error;
size_t i_realloc = i_new_count * 4;
void *p_realloc = realloc( p_text_block->p_uchars, i_realloc );
if( unlikely(!p_realloc) )
- return 0;
+ goto error;
p_text_block->p_uchars = p_realloc;
/* We want one per segment shared text_style_t* per unicode character */
if( SIZE_MAX / sizeof(text_style_t *) < i_new_count )
- return 0;
+ goto error;
i_realloc = i_new_count * sizeof(text_style_t *);
p_realloc = realloc( p_text_block->pp_styles, i_realloc );
if ( unlikely(!p_realloc) )
- return 0;
+ goto error;
p_text_block->pp_styles = p_realloc;
/* Same for ruby text */
if( SIZE_MAX / sizeof(text_segment_ruby_t *) < i_new_count )
- return 0;
+ goto error;
i_realloc = i_new_count * sizeof(text_segment_ruby_t *);
p_realloc = realloc( p_text_block->pp_ruby, i_realloc );
if ( unlikely(!p_realloc) )
- return 0;
+ goto error;
p_text_block->pp_ruby = p_realloc;
/* Copy data */
memcpy( &p_text_block->p_uchars[p_text_block->i_count], p_ucs4, i_newchars * 4 );
free( p_ucs4 );
- text_style_t *p_mgstyle = text_style_Duplicate( p_sys->p_default_style );
+ p_mgstyle = text_style_Duplicate( p_sys->p_default_style );
if ( p_mgstyle == NULL )
return 0;
@@ -910,16 +909,15 @@ static size_t AddTextAndStyles( filter_sys_t *p_sys,
{
p_ucs4 = ToUCS4( psz_rt, &i_bytes );
if( !p_ucs4 )
- return 0;
+ goto error;
p_rubyblock = malloc(sizeof(ruby_block_t));
if( p_rubyblock )
{
p_rubyblock->p_style = text_style_Duplicate( p_mgstyle );
if( !p_rubyblock->p_style )
{
- free( p_ucs4 );
free( p_rubyblock );
- return 0;
+ goto error;
}
p_rubyblock->p_style->i_font_size *= 0.4;
p_rubyblock->p_style->f_font_relsize *= 0.4;
@@ -936,6 +934,10 @@ static size_t AddTextAndStyles( filter_sys_t *p_sys,
p_text_block->i_count += i_newchars;
return i_newchars;
+error:
+ free( p_ucs4 );
+ text_style_Delete( p_mgstyle );
+ return 0;
}
static size_t SegmentsToTextAndStyles( filter_t *p_filter, const text_segment_t *p_segment,
=====================================
modules/text_renderer/freetype/text_layout.h
=====================================
@@ -83,7 +83,7 @@ typedef struct
{
uni_char_t *p_uchars; /*!< array of size \p i_count character codepoints */
text_style_t **pp_styles; /*!< array of size \p i_count character styles */
- ruby_block_t **pp_ruby; /*!< array of size \p */
+ ruby_block_t **pp_ruby; /*!< array of size \p i_count text-layout params*/
size_t i_count; /*!< length of the arrays */
bool b_balanced; /*!< true for grid-mode text */
View it on GitLab: https://code.videolan.org/videolan/vlc/-/compare/0444c75486589a7952bfea86e2b3ba5099cd5ea8...2437956b1335be4d2efa4cafb34ba55b856e79b3
--
View it on GitLab: https://code.videolan.org/videolan/vlc/-/compare/0444c75486589a7952bfea86e2b3ba5099cd5ea8...2437956b1335be4d2efa4cafb34ba55b856e79b3
You're receiving this email because of your account on code.videolan.org.
More information about the vlc-commits
mailing list