Potential memory leak when using commonmark-gfm library
When I attempted to fix a few of the bugs with the markdown rendering, I noticed this in the manpage of the used library:
Convert text (assumed to be a UTF-8 encoded string with length len) from CommonMark Markdown to HTML, returning a null-terminated, UTF-8-encoded string. It is the caller's responsibility to free the returned buffer.
Since that buffer was allocated in the C function, I don't think that python will free it. I could only crudely analyze this however, as I couldn't get Valgrind to run on the VM and Valgrind is not all that compatible with Python.
So I tried to investigate whether this would leak memory. I tried writing a version which calls libc free on the returned buffer from python and one that doesn't and compared the memory usage after using the markdown function for several minutes. I am aware that this isn't all that great, but the difference is quite big:
With free :
vagrant 5732 75.8 5.2 193892 53340 pts/0 S+ 15:20 7:45 python
^
|
Actual used RAM
Without free:
vagrant 6002 97.9 11.5 258328 117112 pts/0 R+ 15:32 7:43 python
^
|
Actual used RAM