Removing memory leak from the pixman library constructor (patch attached)
Lance Arsenault
lanceman at vt.edu
Wed Sep 25 17:12:08 UTC 2024
Hello Pixmen,
I wish to use libpixman.so with my (C code) loadable DSO (dynamic shared
object) library
modules. I wrote a patch that fixes libpixman.so so that memory allocated
in the pixman
library constructor is freed in a (newly added) library destructor
function. When I unload
the last module that depends on libpixman.so I get a memory leak without
the attached
patch.
The attached patch is only 29 lines (total) over 2 files.
I tested it on git commit ffa5645a2d139106a9154406e3b413fad14fe588 HEAD
master
from https://gitlab.freedesktop.org/pixman/pixman
FOOD FOR THOUGHT (i.e. verbose):
This patch fixes my needs, but one might also consider adding a
corresponding "undo-er"
function which corresponds with the get_implementation() function; but it
may be matter of
debate as to how that would be used (if at all) aside from being used in
the library
destructor function (where it sits in this patch).
I was using Valgrind. On my computer (x86 AMD Ryzen 7) libpixman.so made
6 unfreed
malloc() allocations (which the patch fixes). I can provide test scripts
if requested. Currently
my test scripts are integrated in the software package I'm working on. I
wish to write a robust
software package, and hence, that requires that dependency libraries also
be robust (or
whatever you want to call it).
cheers
lance
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.freedesktop.org/archives/pixman/attachments/20240925/7f2908d0/attachment.htm>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: destructor_0.patch
Type: application/x-patch
Size: 1403 bytes
Desc: not available
URL: <https://lists.freedesktop.org/archives/pixman/attachments/20240925/7f2908d0/attachment.bin>
More information about the Pixman
mailing list