diff --git a/src/lceasy.c b/src/lceasy.c index 341b892..c8a1eed 100644 --- a/src/lceasy.c +++ b/src/lceasy.c @@ -39,6 +39,8 @@ lcurl_easy_t *lcurl_geteasy_at(lua_State *L, int i){ static int lcurl_easy_cleanup(lua_State *L){ lcurl_easy_t *p = lcurl_geteasy(L); + int i; + if(p->curl){ curl_easy_cleanup(p->curl); p->curl = NULL; @@ -48,6 +50,27 @@ static int lcurl_easy_cleanup(lua_State *L){ p->storage = lcurl_storage_free(L, p->storage); } + luaL_unref(L, LCURL_LUA_REGISTRY, p->wr.cb_ref); + luaL_unref(L, LCURL_LUA_REGISTRY, p->wr.ud_ref); + luaL_unref(L, LCURL_LUA_REGISTRY, p->rd.cb_ref); + luaL_unref(L, LCURL_LUA_REGISTRY, p->rd.ud_ref); + luaL_unref(L, LCURL_LUA_REGISTRY, p->pr.cb_ref); + luaL_unref(L, LCURL_LUA_REGISTRY, p->pr.ud_ref); + luaL_unref(L, LCURL_LUA_REGISTRY, p->hd.cb_ref); + luaL_unref(L, LCURL_LUA_REGISTRY, p->hd.ud_ref); + luaL_unref(L, LCURL_LUA_REGISTRY, p->rbuffer.ref); + + p->wr.cb_ref = p->wr.ud_ref = LUA_NOREF; + p->rd.cb_ref = p->rd.ud_ref = LUA_NOREF; + p->hd.cb_ref = p->hd.ud_ref = LUA_NOREF; + p->pr.cb_ref = p->pr.ud_ref = LUA_NOREF; + p->rbuffer.ref = LUA_NOREF; + + for(i = 0; i < LCURL_LIST_COUNT; ++i){ + luaL_unref(L, LCURL_LUA_REGISTRY, p->lists[i]); + p->lists[i] = LUA_NOREF; + } + return 0; } diff --git a/src/lchttppost.c b/src/lchttppost.c index e45e393..376cf33 100644 --- a/src/lchttppost.c +++ b/src/lchttppost.c @@ -361,8 +361,7 @@ static int lcurl_hpost_free(lua_State *L){ } if(p->storage != LUA_NOREF){ - lcurl_storage_free(L, p->storage); - p->storage = LUA_NOREF; + p->storage = lcurl_storage_free(L, p->storage); } return 0;