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