Commit 29f83d1dd5e5ad2aeb8408aac3257026ced6dbb3

Ben Wagner 2023-01-12T23:45:12

[base] 'close' callback may not use `stream->memory`. The documentation for `FT_StreamRec::memory` states that it 'shouldn't be touched by stream implementations'. This is true even for internal implementations of the 'close' callback, since it is not guaranteed that `memory` will even be set when the 'close' callback occurs. * src/base/ftobjs.c (new_memory_stream): stash current `memory` in `stream->descriptor`. (memory_stream_close): Use it.

diff --git a/src/base/ftobjs.c b/src/base/ftobjs.c
index cd20f37..186a908 100644
--- a/src/base/ftobjs.c
+++ b/src/base/ftobjs.c
@@ -1672,7 +1672,7 @@
   static void
   memory_stream_close( FT_Stream  stream )
   {
-    FT_Memory  memory = stream->memory;
+    FT_Memory  memory = (FT_Memory)stream->descriptor.pointer;
 
 
     FT_FREE( stream->base );
@@ -1709,7 +1709,8 @@
 
     FT_Stream_OpenMemory( stream, base, size );
 
-    stream->close = close;
+    stream->descriptor.pointer = memory;
+    stream->close              = close;
 
     *astream = stream;