ikorin24 / U8XmlParser

Extremely fast UTF-8 xml parser library
MIT License
95 stars 13 forks source link

Fix memory leak in XmlObjectCore->Dispose method #3

Closed null-l closed 3 years ago

null-l commented 3 years ago

I have found that unmanaged memory is not releasing after Disposing and cleaning-up everything is possible. The problem is calling FreeHGlobal on the pointer that already is Zero

  {
      var data = Interlocked.Exchange(ref Unsafe.AsRef(**_rawByteData**), default);
      if(data != IntPtr.Zero) {
          AllocationSafety.Remove(_byteLength);
          Marshal.FreeHGlobal(**_rawByteData**);
          Unsafe.AsRef(_rawByteData) = IntPtr.Zero;
          Unsafe.AsRef(_byteLength) = 0;
          Unsafe.AsRef(_offset) = 0;
          _nodes.Dispose();
          _attributes.Dispose();
          _optional.Dispose();
          _entities.Dispose();
      }
  }
ikorin24 commented 3 years ago

Thank you very much, this is a fatal bug.

This pull request will be merged into the develop branch. I'll merge it into the master branch soon and release the fixed version.

ikorin24 commented 3 years ago

The PR has been merged into the master branch and now v1.0.2 has been released.

Thank you for your contribution!