fix memory leak in http one-shot requests (#2615)

This commit is contained in:
Javier Peletier 2019-01-16 21:22:07 +01:00 committed by Arnim Läuger
parent ca92cfd362
commit efc9a6b047
1 changed files with 3 additions and 2 deletions

View File

@ -648,10 +648,9 @@ static int http_accumulate_complete(lua_State *L)
lua_rawseti(L, cache_table, i); lua_rawseti(L, cache_table, i);
} }
luaL_pushresult(&b); // data now pushed luaL_pushresult(&b); // data now pushed
lhttp_context_t *context = (lhttp_context_t *)luaL_checkudata(L, context_idx, http_context_mt);
if (lua_isnoneornil(L, 1)) { if (lua_isnoneornil(L, 1)) {
// No callback fn so must be sync, meaning just need to stash headers and data in the context // No callback fn so must be sync, meaning just need to stash headers and data in the context
lhttp_context_t *context = (lhttp_context_t *)luaL_checkudata(L, context_idx, http_context_mt);
// steal some completion refs, nothing's going to need them again in a one-shot // steal some completion refs, nothing's going to need them again in a one-shot
context_setref(L, context, DataCallback); // pops data context_setref(L, context, DataCallback); // pops data
lua_rawgeti(L, cache_table, 2); // headers lua_rawgeti(L, cache_table, 2); // headers
@ -660,6 +659,8 @@ static int http_accumulate_complete(lua_State *L)
lua_rawgeti(L, cache_table, 2); // headers lua_rawgeti(L, cache_table, 2); // headers
lua_call(L, 3, 0); lua_call(L, 3, 0);
} }
// unset this since it contains a reference to the context and would prevent the context to be garbage collected
context_unsetref(L, context,CompleteCallback);
return 0; return 0;
} }