-
Notifications
You must be signed in to change notification settings - Fork 85
Open
Description
Recently I met a segment fault issue ,and finally found that when calling get_url_field in turbo httputils.lua, ffi.gc is called with the wrong paramter.
ffi.gc(htpurl, ffi.C.free)
htpurl is a temporary pointer, which goes out of scope and will eventually be collected.
It should be changed to ffi.gc(self.http_parser_url, ffi.C.free) and put it after:
self.http_parser_url = ffi.cast("struct http_parser_url *", htpurl)
function httputil.HTTPParser:parse_url(url)
if type(url) ~= "string" then
error("URL parameter is not a string")
end
local htpurl = ffi.C.malloc(ffi.sizeof("struct http_parser_url"))
if htpurl == nil then
error("Could not allocate memory")
end
ffi.gc(htpurl, ffi.C.free)
self.http_parser_url = ffi.cast("struct http_parser_url *", htpurl)
local rc = libturbo_parser.http_parser_parse_url(
url,
url:len(),
0,
self.http_parser_url)
if rc ~= 0 then
error("Could not parse URL")
end
if not self.url then
self.url = url
end
end
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels