diff options
author | Ronan Collobert <ronan@collobert.com> | 2014-03-20 14:53:38 +0400 |
---|---|---|
committer | Ronan Collobert <ronan@collobert.com> | 2014-03-20 14:53:38 +0400 |
commit | 812223802c9c9f359b46478b7bbb1d5b154a88ac (patch) | |
tree | f951f70b49dad580391ca6ba160e8cf7f51766c6 | |
parent | aaab223118159ee3d58f4754bb41c39c838d8ddd (diff) |
fix mem leak in html renderer
-rw-r--r-- | html.lua | 12 |
1 files changed, 4 insertions, 8 deletions
@@ -9,19 +9,15 @@ local function render(txt) local callbacks = ffi.new('struct sd_callbacks') local options = ffi.new('struct sd_html_renderopt') C.sd_html_renderer(callbacks, options, 0) - local markdown = C.sd_markdown_new(0xfff, 16, callbacks, options) - local outbuf = ffi.new('struct sd_buf') - outbuf.data = nil - outbuf.size = 0 - outbuf.asize = 0 - outbuf.unit = 64 - + local outbuf = C.sd_bufnew(64) C.sd_markdown_render(outbuf, ffi.cast('const char*', txt), #txt, markdown) C.sd_markdown_free(markdown) + txt = ffi.string(outbuf.data, outbuf.size) + C.sd_bufrelease(outbuf) - return ffi.string(outbuf.data, outbuf.size) + return txt end return {render=render} |