diff --git a/components/modules/http.c b/components/modules/http.c index e0e4b43d..d9ccad13 100644 --- a/components/modules/http.c +++ b/components/modules/http.c @@ -648,10 +648,9 @@ static int http_accumulate_complete(lua_State *L) lua_rawseti(L, cache_table, i); } 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)) { // 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 context_setref(L, context, DataCallback); // pops data 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_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; }