[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.
This commit is contained in:
Alexei Podtelezhnikov 2021-09-22 00:30:03 -04:00
parent 93866bec77
commit b4dddd8244
3 changed files with 11 additions and 11 deletions

View File

@ -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 );

View File

@ -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 );

View File

@ -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;