Product: PDFTron
Product Version: 9.4
Please give a brief summary of your issue:
(Think of this as an email subject)
While debugging a recent issue I noticed this code within the PDFTron .net SDK:
public unsafe void Save(Stream stm, SDFDoc.SaveOptions flags)
{
uint flags2 = System.Convert.ToUInt32(flags);
PDFNetException.REX(PDFNetPINVOKE.TRN_PDFDocSaveMemoryBuffer(mp_doc, flags2, out var result_buf, out var out_buf_size));
byte* pointer = (byte*)result_buf.ToPointer();
using (UnmanagedMemoryStream unmanagedMemoryStream = new UnmanagedMemoryStream(pointer, out_buf_size.ToUInt32()))
{
if (stm.CanSeek)
{
stm.Position = 0L;
}
if (unmanagedMemoryStream.CanSeek)
{
unmanagedMemoryStream.Position = 0L;
}
unmanagedMemoryStream.CopyTo(stm);
}
GC.KeepAlive(this);
}
It appears that here, PDFNetPINVOKE.TRN_PDFDocSaveMemoryBuffer is returning an unmanaged buffer, and UnmanagedMemoryStream is being used to copy the contents of that buffer to the stream passed in to the Save method.
I don’t see the unmanaged buffer result_buf being freed. The documentation to UnmanagedMemoryStream does not state that it will free the buffer passed to it. Therefore it would seem that the memory allocated by TRN_PDFDocSaveMemoryBuffer is being leaked, or am I missing something?
I ask because we had to roll back a recent production deployment which makes extensive use of PDFTron, and the issues seemed to be resource-related.
Best regards,
Peter
Please describe your issue and provide steps to reproduce it:
(The more descriptive your answer, the faster we are able to help you)
Please provide a link to a minimal sample where the issue is reproducible: