@@ -130,31 +130,12 @@ static int lcurl_easy_to_s(lua_State *L){
|
130 | 130 | return 1;
|
131 | 131 | }
|
132 | 132 |
|
133 |
| -static int lcurl_easy_cleanup(lua_State *L){ |
134 |
| -lcurl_easy_t *p = lcurl_geteasy(L); |
| 133 | +static int lcurl_easy_cleanup_storage(lua_State *L, lcurl_easy_t *p){ |
| 134 | +int top = lua_gettop(L); |
135 | 135 | int i;
|
136 | 136 |
|
137 |
| -if(p->multi){ |
138 |
| -LCURL_UNUSED_VAR CURLMcode code = lcurl__multi_remove_handle(L, p->multi, p); |
139 |
| - |
140 |
| -//! @todo what I can do if I can not remove it??? |
141 |
| -} |
142 |
| - |
143 |
| -if(p->curl){ |
144 |
| -lua_State *curL; |
145 |
| - |
146 |
| -// In my tests when I cleanup some easy handle. |
147 |
| -// timerfunction called only for single multi handle. |
148 |
| -// Also may be this function may call `close` callback |
149 |
| -// for `curl_mimepart` structure. |
150 |
| -curL = p->L; lcurl__easy_assign_lua(L, p, L, 1); |
151 |
| -curl_easy_cleanup(p->curl); |
152 |
| -#ifndef LCURL_RESET_NULL_LUA |
153 |
| -if(curL != NULL) |
154 |
| -#endif |
155 |
| -lcurl__easy_assign_lua(L, p, curL, 1); |
156 |
| - |
157 |
| -p->curl = NULL; |
| 137 | +if(p->storage != LUA_NOREF){ |
| 138 | +p->storage = lcurl_storage_free(L, p->storage); |
158 | 139 | }
|
159 | 140 |
|
160 | 141 | p->post = NULL;
|
@@ -166,10 +147,6 @@ static int lcurl_easy_cleanup(lua_State *L){
|
166 | 147 | p->url = NULL;
|
167 | 148 | #endif
|
168 | 149 |
|
169 |
| -if(p->storage != LUA_NOREF){ |
170 |
| -p->storage = lcurl_storage_free(L, p->storage); |
171 |
| -} |
172 |
| - |
173 | 150 | luaL_unref(L, LCURL_LUA_REGISTRY, p->wr.cb_ref);
|
174 | 151 | luaL_unref(L, LCURL_LUA_REGISTRY, p->wr.ud_ref);
|
175 | 152 | luaL_unref(L, LCURL_LUA_REGISTRY, p->rd.cb_ref);
|
@@ -222,7 +199,38 @@ static int lcurl_easy_cleanup(lua_State *L){
|
222 | 199 | p->lists[i] = LUA_NOREF;
|
223 | 200 | }
|
224 | 201 |
|
| 202 | +assert(lua_gettop(L) == top); |
| 203 | +} |
| 204 | + |
| 205 | +static int lcurl_easy_cleanup(lua_State *L){ |
| 206 | +lcurl_easy_t *p = lcurl_geteasy(L); |
225 | 207 | lua_settop(L, 1);
|
| 208 | + |
| 209 | +if(p->multi){ |
| 210 | +LCURL_UNUSED_VAR CURLMcode code = lcurl__multi_remove_handle(L, p->multi, p); |
| 211 | + |
| 212 | +//! @todo what I can do if I can not remove it??? |
| 213 | +} |
| 214 | + |
| 215 | +if(p->curl){ |
| 216 | +lua_State *curL; |
| 217 | + |
| 218 | +// In my tests when I cleanup some easy handle. |
| 219 | +// timerfunction called only for single multi handle. |
| 220 | +// Also may be this function may call `close` callback |
| 221 | +// for `curl_mimepart` structure. |
| 222 | +curL = p->L; lcurl__easy_assign_lua(L, p, L, 1); |
| 223 | +curl_easy_cleanup(p->curl); |
| 224 | +#ifndef LCURL_RESET_NULL_LUA |
| 225 | +if(curL != NULL) |
| 226 | +#endif |
| 227 | +lcurl__easy_assign_lua(L, p, curL, 1); |
| 228 | + |
| 229 | +p->curl = NULL; |
| 230 | +} |
| 231 | + |
| 232 | +lcurl_easy_cleanup_storage(L, p); |
| 233 | + |
226 | 234 | lua_pushnil(L);
|
227 | 235 | lua_rawset(L, LCURL_USERVALUES);
|
228 | 236 |
|
@@ -305,15 +313,8 @@ static int lcurl_easy_reset(lua_State *L){
|
305 | 313 | curl_easy_reset(p->curl);
|
306 | 314 | lua_settop(L, 1);
|
307 | 315 |
|
308 |
| -if(p->storage != LUA_NOREF){ |
309 |
| -int i; |
310 |
| -for (i = 0; i < LCURL_LIST_COUNT; ++i) { |
311 |
| -p->lists[i] = LUA_NOREF; |
312 |
| -} |
313 |
| -lcurl_storage_free(L, p->storage); |
314 |
| -p->storage = lcurl_storage_init(L); |
315 |
| -lua_settop(L, 1); |
316 |
| -} |
| 316 | +lcurl_easy_cleanup_storage(L, p); |
| 317 | +p->storage = lcurl_storage_init(L); |
317 | 318 |
|
318 | 319 | return 1;
|
319 | 320 | }
|
|
0 commit comments