Merge pull request #7 from zhaozg/master

fix mem leaks bug, unref cb data when easy/multi cleanup
This commit is contained in:
Alexey Melnichuk 2014-08-30 01:23:59 +00:00
commit 0191e5cdec
3 changed files with 28 additions and 3 deletions

View File

@ -39,6 +39,8 @@ lcurl_easy_t *lcurl_geteasy_at(lua_State *L, int i){
static int lcurl_easy_cleanup(lua_State *L){ static int lcurl_easy_cleanup(lua_State *L){
lcurl_easy_t *p = lcurl_geteasy(L); lcurl_easy_t *p = lcurl_geteasy(L);
int i;
if(p->curl){ if(p->curl){
curl_easy_cleanup(p->curl); curl_easy_cleanup(p->curl);
p->curl = NULL; p->curl = NULL;
@ -48,6 +50,27 @@ static int lcurl_easy_cleanup(lua_State *L){
p->storage = lcurl_storage_free(L, p->storage); 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; return 0;
} }

View File

@ -361,8 +361,7 @@ static int lcurl_hpost_free(lua_State *L){
} }
if(p->storage != LUA_NOREF){ if(p->storage != LUA_NOREF){
lcurl_storage_free(L, p->storage); p->storage = lcurl_storage_free(L, p->storage);
p->storage = LUA_NOREF;
} }
return 0; return 0;

View File

@ -51,6 +51,9 @@ static int lcurl_multi_cleanup(lua_State *L){
p->h_ref = LUA_NOREF; p->h_ref = LUA_NOREF;
} }
luaL_unref(L, LCURL_LUA_REGISTRY, p->tm.cb_ref);
luaL_unref(L, LCURL_LUA_REGISTRY, p->tm.ud_ref);
p->tm.cb_ref = p->tm.ud_ref = LUA_NOREF;
return 0; return 0;
} }