[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
RE: [Devel] potential of memory leaking in kern
From: |
Turner David |
Subject: |
RE: [Devel] potential of memory leaking in kern |
Date: |
Wed, 12 Nov 2003 13:39:16 +0100 |
Hello,
> -----Original Message-----
> From: address@hidden [mailto:address@hidden
> Behalf Of Masatake YAMATO
> Sent: Wednesday, November 12, 2003 1:09 PM
> To: address@hidden
> Subject: [Devel] potential of memory leaking in kern
>
>
> Hi,
>
> In tt_face_load_kern, the results of FT_NEW_ARRAY and FT_FRAME_ENTER
> are checkd in single if-condition. If FT_NEW_ARRAY is successful but
> FT_FRAME_ENTER is failed, the buffer allocated by FT_NEW_ARRAY will
> be never freed.
>
That's not true, it will be freed when the face will be closed, i.e.
most likely when FT_Done_Face will be called. This technique is used
very widely in the engine, it consists of:
- using object destructors as the _only_ location where object fields
are released
- initializing / loading functions shall report errors as soon as
possible, but shouldn't perform object field cleanup
- however, some cleanup may be needed for temporary data allocated
within an operation that isn't stored directly as an object field
(e.g. temporary buffers)
Your patch fixes the following issue though:
- in case of a font file with a broken kerning table, the engine
_may_ allocate more memory than strictly needed in a FT_Face object
Thanks for your report,
- David Turner
- The FreeType Project (www.freetype.org)
> Masatake YAMATO
>
> 2003-11-12 Masatake YAMATO <address@hidden>
>
> * src/sfnt/ttload.c (tt_face_load_kern):
> Before jumping to Exit, free face->kern_pairs if
> FT_FRAME_ENTER is failed.
>
> Index: src/sfnt/ttload.c
> ===================================================================
> RCS file: /cvsroot/freetype2/src/sfnt/ttload.c,v
> retrieving revision 1.102
> diff -u -r1.102 ttload.c
> --- ttload.c 2003/06/30 13:08:58 1.102
> +++ ttload.c 2003/11/12 12:04:43
> @@ -1674,9 +1674,13 @@
> FT_FRAME_EXIT();
>
> /* allocate array of kerning pairs */
> - if ( FT_NEW_ARRAY( face->kern_pairs, num_pairs ) ||
> - FT_FRAME_ENTER( 6L * num_pairs ) )
> - goto Exit;
> + if ( FT_NEW_ARRAY( face->kern_pairs, num_pairs ) )
> + goto Exit;
> + if ( FT_FRAME_ENTER( 6L * num_pairs ) )
> + {
> + FT_FREE( face->kern_pairs );
> + goto Exit;
> + }
>
> pair = face->kern_pairs;
> limit = pair + num_pairs;
>
> _______________________________________________
> Devel mailing list
> address@hidden
> http://www.freetype.org/mailman/listinfo/devel
>
--
This message and any attachments (the "message") is intended solely for the
addressees and is confidential. If you receive this message in error, please
delete it and immediately notify the sender.
Any use not in accordance with its purpose, any dissemination or disclosure,
either whole or partial, is prohibited except formal approval.
The E-Mail transmission can not guarantee the integrity of this message.
CANAL+TECHNOLOGIES will not therefore be liable for the message if modified.