@@ -83,9 +83,6 @@ int lcurl_easy_create(lua_State *L, int error_mode){
8383 p -> multi = NULL ;
8484#if LCURL_CURL_VER_GE (7 ,56 ,0 )
8585 p -> mime = NULL ;
86- #endif
87- #if LCURL_CURL_VER_GE (7 ,63 ,0 )
88- p -> url = NULL ;
8986#endif
9087 p -> storage = lcurl_storage_init (L );
9188 p -> wr .cb_ref = p -> wr .ud_ref = LUA_NOREF ;
@@ -130,46 +127,18 @@ static int lcurl_easy_to_s(lua_State *L){
130127 return 1 ;
131128}
132129
133- static int lcurl_easy_cleanup (lua_State * L ){
134- lcurl_easy_t * p = lcurl_geteasy (L );
130+ static int lcurl_easy_cleanup_storage (lua_State * L , lcurl_easy_t * p ){
135131 int i ;
136132
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 ;
133+ if (p -> storage != LUA_NOREF ){
134+ p -> storage = lcurl_storage_free (L , p -> storage );
158135 }
159136
160137 p -> post = NULL ;
161138#if LCURL_CURL_VER_GE (7 ,56 ,0 )
162139 p -> mime = NULL ;
163140#endif
164141
165- #if LCURL_CURL_VER_GE (7 ,63 ,0 )
166- p -> url = NULL ;
167- #endif
168-
169- if (p -> storage != LUA_NOREF ){
170- p -> storage = lcurl_storage_free (L , p -> storage );
171- }
172-
173142 luaL_unref (L , LCURL_LUA_REGISTRY , p -> wr .cb_ref );
174143 luaL_unref (L , LCURL_LUA_REGISTRY , p -> wr .ud_ref );
175144 luaL_unref (L , LCURL_LUA_REGISTRY , p -> rd .cb_ref );
@@ -221,8 +190,37 @@ static int lcurl_easy_cleanup(lua_State *L){
221190 for (i = 0 ; i < LCURL_LIST_COUNT ; ++ i ){
222191 p -> lists [i ] = LUA_NOREF ;
223192 }
193+ }
224194
195+ static int lcurl_easy_cleanup (lua_State * L ){
196+ lcurl_easy_t * p = lcurl_geteasy (L );
225197 lua_settop (L , 1 );
198+
199+ if (p -> multi ){
200+ LCURL_UNUSED_VAR CURLMcode code = lcurl__multi_remove_handle (L , p -> multi , p );
201+
202+ //! @todo what I can do if I can not remove it???
203+ }
204+
205+ if (p -> curl ){
206+ lua_State * curL ;
207+
208+ // In my tests when I cleanup some easy handle.
209+ // timerfunction called only for single multi handle.
210+ // Also may be this function may call `close` callback
211+ // for `curl_mimepart` structure.
212+ curL = p -> L ; lcurl__easy_assign_lua (L , p , L , 1 );
213+ curl_easy_cleanup (p -> curl );
214+ #ifndef LCURL_RESET_NULL_LUA
215+ if (curL != NULL )
216+ #endif
217+ lcurl__easy_assign_lua (L , p , curL , 1 );
218+
219+ p -> curl = NULL ;
220+ }
221+
222+ lcurl_easy_cleanup_storage (L , p );
223+
226224 lua_pushnil (L );
227225 lua_rawset (L , LCURL_USERVALUES );
228226
@@ -305,15 +303,8 @@ static int lcurl_easy_reset(lua_State *L){
305303 curl_easy_reset (p -> curl );
306304 lua_settop (L , 1 );
307305
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- }
306+ lcurl_easy_cleanup_storage (L , p );
307+ p -> storage = lcurl_storage_init (L );
317308
318309 return 1 ;
319310}
@@ -621,8 +612,6 @@ static int lcurl_easy_set_CURLU(lua_State *L) {
621612
622613 lcurl_storage_preserve_iv (L , p -> storage , CURLOPT_CURLU , 2 );
623614
624- p -> url = url ;
625-
626615 lua_settop (L , 1 );
627616 return 1 ;
628617}
@@ -1030,8 +1019,6 @@ static int lcurl_easy_unset_CURLU(lua_State *L) {
10301019
10311020 lcurl_storage_remove_i (L , p -> storage , CURLOPT_CURLU );
10321021
1033- p -> url = NULL ;
1034-
10351022 lua_settop (L , 1 );
10361023 return 1 ;
10371024}
0 commit comments