Fix various memory problems found by linuxtesting.org.

* src/base/ftgxval.c (FT_TrueTypeGX_Free, FT_ClassicKern_Free),
src/base/ftotval.c (FT_OpenType_Free), src/base/ftpfr.c
(ft_pfr_check): Check `face'.

* src/base/ftobjs.c (FT_Get_Charmap_Index): Check `charmap' and
`charmap->face'.
(FT_Render_Glyph): Check `slot->face'.
(FT_Get_SubGlyph_Info): Check `glyph->subglyphs'.

Improve API documentation.
This commit is contained in:
Werner Lemberg 2010-05-22 20:03:41 +02:00
parent 09344385ee
commit e30de299f2
8 changed files with 56 additions and 13 deletions

View File

@ -1,3 +1,16 @@
2010-05-22 Werner Lemberg <wl@gnu.org>
Fix various memory problems found by linuxtesting.org.
* src/base/ftgxval.c (FT_TrueTypeGX_Free, FT_ClassicKern_Free),
src/base/ftotval.c (FT_OpenType_Free), src/base/ftpfr.c
(ft_pfr_check): Check `face'.
* src/base/ftobjs.c (FT_Get_Charmap_Index): Check `charmap' and
`charmap->face'.
(FT_Render_Glyph): Check `slot->face'.
(FT_Get_SubGlyph_Info): Check `glyph->subglyphs'.
2010-05-22 Werner Lemberg <wl@gnu.org> 2010-05-22 Werner Lemberg <wl@gnu.org>
autofit: Remove dead code. autofit: Remove dead code.

View File

@ -2997,7 +2997,7 @@ FT_BEGIN_HEADER
* *
* @return: * @return:
* The index into the array of character maps within the face to which * The index into the array of character maps within the face to which
* `charmap' belongs. * `charmap' belongs. If an error occurs, -1 is returned.
* *
*/ */
FT_EXPORT( FT_Int ) FT_EXPORT( FT_Int )

View File

@ -4,7 +4,7 @@
/* */ /* */
/* Generic list support for FreeType (specification). */ /* Generic list support for FreeType (specification). */
/* */ /* */
/* Copyright 1996-2001, 2003, 2007 by */ /* Copyright 1996-2001, 2003, 2007, 2010 by */
/* David Turner, Robert Wilhelm, and Werner Lemberg. */ /* David Turner, Robert Wilhelm, and Werner Lemberg. */
/* */ /* */
/* This file is part of the FreeType project, and may only be used, */ /* This file is part of the FreeType project, and may only be used, */
@ -255,6 +255,10 @@ FT_BEGIN_HEADER
/* user :: A user-supplied field which is passed as the last */ /* user :: A user-supplied field which is passed as the last */
/* argument to the destructor. */ /* argument to the destructor. */
/* */ /* */
/* <Note> */
/* This function expects that all nodes added by @FT_List_Add or */
/* @FT_List_Insert have been dynamically allocated. */
/* */
FT_EXPORT( void ) FT_EXPORT( void )
FT_List_Finalize( FT_List list, FT_List_Finalize( FT_List list,
FT_List_Destructor destroy, FT_List_Destructor destroy,

View File

@ -4,7 +4,7 @@
/* */ /* */
/* FreeType modules public interface (specification). */ /* FreeType modules public interface (specification). */
/* */ /* */
/* Copyright 1996-2001, 2002, 2003, 2006, 2008, 2009 by */ /* Copyright 1996-2001, 2002, 2003, 2006, 2008, 2009, 2010 by */
/* David Turner, Robert Wilhelm, and Werner Lemberg. */ /* David Turner, Robert Wilhelm, and Werner Lemberg. */
/* */ /* */
/* This file is part of the FreeType project, and may only be used, */ /* This file is part of the FreeType project, and may only be used, */
@ -263,6 +263,9 @@ FT_BEGIN_HEADER
/* @FT_Add_Default_Modules or a series of calls to @FT_Add_Module) */ /* @FT_Add_Default_Modules or a series of calls to @FT_Add_Module) */
/* instead of @FT_Init_FreeType to initialize the FreeType library. */ /* instead of @FT_Init_FreeType to initialize the FreeType library. */
/* */ /* */
/* Don't use @FT_Done_FreeType but @FT_Done_Library to destroy a */
/* library instance. */
/* */
/* <Input> */ /* <Input> */
/* memory :: A handle to the original memory object. */ /* memory :: A handle to the original memory object. */
/* */ /* */

View File

@ -4,7 +4,7 @@
/* */ /* */
/* FreeType API for validating TrueTyepGX/AAT tables (body). */ /* FreeType API for validating TrueTyepGX/AAT tables (body). */
/* */ /* */
/* Copyright 2004, 2005, 2006 by */ /* Copyright 2004, 2005, 2006, 2010 by */
/* Masatake YAMATO, Redhat K.K, */ /* Masatake YAMATO, Redhat K.K, */
/* David Turner, Robert Wilhelm, and Werner Lemberg. */ /* David Turner, Robert Wilhelm, and Werner Lemberg. */
/* */ /* */
@ -73,9 +73,14 @@
FT_TrueTypeGX_Free( FT_Face face, FT_TrueTypeGX_Free( FT_Face face,
FT_Bytes table ) FT_Bytes table )
{ {
FT_Memory memory = FT_FACE_MEMORY( face ); FT_Memory memory;
if ( !face )
return;
memory = FT_FACE_MEMORY( face );
FT_FREE( table ); FT_FREE( table );
} }
@ -119,7 +124,13 @@
FT_ClassicKern_Free( FT_Face face, FT_ClassicKern_Free( FT_Face face,
FT_Bytes table ) FT_Bytes table )
{ {
FT_Memory memory = FT_FACE_MEMORY( face ); FT_Memory memory;
if ( !face )
return;
memory = FT_FACE_MEMORY( face );
FT_FREE( table ); FT_FREE( table );

View File

@ -2950,6 +2950,9 @@
FT_Int i; FT_Int i;
if ( !charmap || !charmap->face )
return -1;
for ( i = 0; i < charmap->face->num_charmaps; i++ ) for ( i = 0; i < charmap->face->num_charmaps; i++ )
if ( charmap->face->charmaps[i] == charmap ) if ( charmap->face->charmaps[i] == charmap )
break; break;
@ -3844,7 +3847,7 @@
FT_Library library; FT_Library library;
if ( !slot ) if ( !slot || !slot->face )
return FT_Err_Invalid_Argument; return FT_Err_Invalid_Argument;
library = FT_FACE_LIBRARY( slot->face ); library = FT_FACE_LIBRARY( slot->face );
@ -4469,6 +4472,8 @@
#endif /* FT_CONFIG_OPTION_OLD_INTERNALS */ #endif /* FT_CONFIG_OPTION_OLD_INTERNALS */
/* documentation is in freetype.h */
FT_EXPORT_DEF( FT_Error ) FT_EXPORT_DEF( FT_Error )
FT_Get_SubGlyph_Info( FT_GlyphSlot glyph, FT_Get_SubGlyph_Info( FT_GlyphSlot glyph,
FT_UInt sub_index, FT_UInt sub_index,
@ -4481,7 +4486,8 @@
FT_Error error = FT_Err_Invalid_Argument; FT_Error error = FT_Err_Invalid_Argument;
if ( glyph != NULL && if ( glyph &&
glyph->subglyphs &&
glyph->format == FT_GLYPH_FORMAT_COMPOSITE && glyph->format == FT_GLYPH_FORMAT_COMPOSITE &&
sub_index < glyph->num_subglyphs ) sub_index < glyph->num_subglyphs )
{ {

View File

@ -4,7 +4,7 @@
/* */ /* */
/* FreeType API for validating OpenType tables (body). */ /* FreeType API for validating OpenType tables (body). */
/* */ /* */
/* Copyright 2004, 2006, 2008 by */ /* Copyright 2004, 2006, 2008, 2010 by */
/* David Turner, Robert Wilhelm, and Werner Lemberg. */ /* David Turner, Robert Wilhelm, and Werner Lemberg. */
/* */ /* */
/* This file is part of the FreeType project, and may only be used, */ /* This file is part of the FreeType project, and may only be used, */
@ -74,9 +74,14 @@
FT_OpenType_Free( FT_Face face, FT_OpenType_Free( FT_Face face,
FT_Bytes table ) FT_Bytes table )
{ {
FT_Memory memory = FT_FACE_MEMORY( face ); FT_Memory memory;
if ( !face )
return;
memory = FT_FACE_MEMORY( face );
FT_FREE( table ); FT_FREE( table );
} }

View File

@ -4,7 +4,7 @@
/* */ /* */
/* FreeType API for accessing PFR-specific data (body). */ /* FreeType API for accessing PFR-specific data (body). */
/* */ /* */
/* Copyright 2002, 2003, 2004, 2008 by */ /* Copyright 2002, 2003, 2004, 2008, 2010 by */
/* David Turner, Robert Wilhelm, and Werner Lemberg. */ /* David Turner, Robert Wilhelm, and Werner Lemberg. */
/* */ /* */
/* This file is part of the FreeType project, and may only be used, */ /* This file is part of the FreeType project, and may only be used, */
@ -24,10 +24,11 @@
static FT_Service_PfrMetrics static FT_Service_PfrMetrics
ft_pfr_check( FT_Face face ) ft_pfr_check( FT_Face face )
{ {
FT_Service_PfrMetrics service; FT_Service_PfrMetrics service = NULL;
FT_FACE_LOOKUP_SERVICE( face, service, PFR_METRICS ); if ( face )
FT_FACE_LOOKUP_SERVICE( face, service, PFR_METRICS );
return service; return service;
} }