ref: b4dddd8244fb59795f030530ad2b401ec4d5b477
parent: 93866bec77bee6479d8103175562c4fe472c3529
author: Alexei Podtelezhnikov <[email protected]>
date: Tue Sep 21 20:30:03 EDT 2021
[base] Initialize stream memory earlier. With Windows memory management tracking heap, it is important to use it during the stream opening fallback. In Unix, the argument is unused, but it is better to set it correctly. * src/base/ftobjs.c (FT_Stream_New): Set memory before calling `FT_Stream_Open`. * builds/windows/ftsystem.c, builds/unix/ftsystem.c (FT_Stream_Open, ft_close_stream_by_free): Call `ft_alloc` and `ft_free` with proper memory argumment.
--- a/builds/unix/ftsystem.c
+++ b/builds/unix/ftsystem.c
@@ -233,7 +233,7 @@
FT_CALLBACK_DEF( void )
ft_close_stream_by_free( FT_Stream stream )
{
- ft_free( NULL, stream->descriptor.pointer );
+ ft_free( stream->memory, stream->descriptor.pointer );
stream->descriptor.pointer = NULL;
stream->size = 0;
@@ -324,7 +324,7 @@
FT_ERROR(( "FT_Stream_Open:" ));
FT_ERROR(( " could not `mmap' file `%s'\n", filepathname ));
- stream->base = (unsigned char*)ft_alloc( NULL, stream->size );
+ stream->base = (unsigned char*)ft_alloc( stream->memory, stream->size );
if ( !stream->base )
{
@@ -374,7 +374,7 @@
return FT_Err_Ok;
Fail_Read:
- ft_free( NULL, stream->base );
+ ft_free( stream->memory, stream->base );
Fail_Map:
close( file );
--- a/builds/windows/ftsystem.c
+++ b/builds/windows/ftsystem.c
@@ -188,7 +188,7 @@
FT_CALLBACK_DEF( void )
ft_close_stream_by_free( FT_Stream stream )
{
- ft_free( NULL, stream->descriptor.pointer );
+ ft_free( stream->memory, stream->descriptor.pointer );
stream->descriptor.pointer = NULL;
stream->size = 0;
@@ -323,7 +323,7 @@
FT_ERROR(( "FT_Stream_Open:" ));
FT_ERROR(( " could not `mmap' file `%s'\n", filepathname ));
- stream->base = (unsigned char*)ft_alloc( NULL, stream->size );
+ stream->base = (unsigned char*)ft_alloc( stream->memory, stream->size );
if ( !stream->base )
{
@@ -369,7 +369,7 @@
return FT_Err_Ok;
Fail_Read:
- ft_free( NULL, stream->base );
+ ft_free( stream->memory, stream->base );
Fail_Open:
CloseHandle( file );
--- a/src/base/ftobjs.c
+++ b/src/base/ftobjs.c
@@ -221,6 +221,7 @@
FT_Stream_OpenMemory( stream,
(const FT_Byte*)args->memory_base,
(FT_ULong)args->memory_size );
+ stream->memory = memory;
}
#ifndef FT_CONFIG_OPTION_DISABLE_STREAM_SUPPORT
@@ -231,6 +232,7 @@
if ( FT_NEW( stream ) )
goto Exit;
+ stream->memory = memory;
error = FT_Stream_Open( stream, args->pathname );
if ( error )
FT_FREE( stream );
@@ -241,8 +243,9 @@
/* in this case, we do not need to allocate a new stream object */
/* since the caller is responsible for closing it himself */
- stream = args->stream;
- error = FT_Err_Ok;
+ stream = args->stream;
+ stream->memory = memory;
+ error = FT_Err_Ok;
}
#endif
@@ -255,10 +258,7 @@
}
if ( !error )
- {
- stream->memory = memory;
*astream = stream;
- }
Exit:
return error;