Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/torch/sundown-ffi.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRonan Collobert <ronan@collobert.com>2014-03-20 14:53:38 +0400
committerRonan Collobert <ronan@collobert.com>2014-03-20 14:53:38 +0400
commit812223802c9c9f359b46478b7bbb1d5b154a88ac (patch)
treef951f70b49dad580391ca6ba160e8cf7f51766c6
parentaaab223118159ee3d58f4754bb41c39c838d8ddd (diff)
fix mem leak in html renderer
-rw-r--r--html.lua12
1 files changed, 4 insertions, 8 deletions
diff --git a/html.lua b/html.lua
index 9f03f39..349cfec 100644
--- a/html.lua
+++ b/html.lua
@@ -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}