Get the latest tech news

Fixing a memory leak of xmlEntityPtr in librsvg


Since a few weeks ago, librsvg is now in oss-fuzz — Google's constantly-running fuzz-testing for OSS projects — and the crashes have started coming in. I'll have a lot more to say soon about crashes in Cairo, which is where the majority of the bugs are so far, but for now I want to tell you about a little bug I just fixed.

Librsvg uses the SAX parser, which involves setting up callbacks to process events like "XML element started", or "an entity was defined". The magic of having an impl Drop for a wrapper around an unmanaged resource, like xmlEntityPtr, is that Rust will automatically call that destructor at the appropriate time — in this case, when the hash table is freed. In this case, wrapping xmlEntityPtr with a newtype and adding an impl Drop is all that is needed for the rest of the code to look like it's handling a normal, automatically-managed Rust object.

Get the Android app

Or read this on Hacker News

Read more on:

Photo of memory leak

memory leak

Photo of xmlEntityPtr

xmlEntityPtr

Photo of librsvg

librsvg

Related news:

News photo

So We've Got a Memory Leak

News photo

Microsoft Confirms Windows Server Security Update Caused Memory Leak, 'Unscheduled' Reboots

News photo

Windows 10 KB5031445 preview update fixes ctfmon.exe memory leak, 9 issues