@@ -571,6 +571,10 @@ static int lcurl_easy_unset_WRITEFUNCTION(lua_State *L){
571571 }
572572 curl_easy_setopt (p -> curl , CURLOPT_WRITEDATA , NULL );
573573
574+ luaL_unref (L , LCURL_LUA_REGISTRY , p -> wr .cb_ref );
575+ luaL_unref (L , LCURL_LUA_REGISTRY , p -> wr .ud_ref );
576+ p -> wr .cb_ref = p -> wr .ud_ref = LUA_NOREF ;
577+
574578 lua_settop (L , 1 );
575579 return 1 ;
576580}
@@ -584,6 +588,10 @@ static int lcurl_easy_unset_READFUNCTION(lua_State *L){
584588 }
585589 curl_easy_setopt (p -> curl , CURLOPT_READDATA , NULL );
586590
591+ luaL_unref (L , LCURL_LUA_REGISTRY , p -> rd .cb_ref );
592+ luaL_unref (L , LCURL_LUA_REGISTRY , p -> rd .ud_ref );
593+ p -> rd .cb_ref = p -> rd .ud_ref = LUA_NOREF ;
594+
587595 lua_settop (L , 1 );
588596 return 1 ;
589597}
@@ -597,6 +605,10 @@ static int lcurl_easy_unset_HEADERFUNCTION(lua_State *L){
597605 }
598606 curl_easy_setopt (p -> curl , CURLOPT_HEADERDATA , NULL );
599607
608+ luaL_unref (L , LCURL_LUA_REGISTRY , p -> hd .cb_ref );
609+ luaL_unref (L , LCURL_LUA_REGISTRY , p -> hd .ud_ref );
610+ p -> hd .cb_ref = p -> hd .ud_ref = LUA_NOREF ;
611+
600612 lua_settop (L , 1 );
601613 return 1 ;
602614}
@@ -615,6 +627,10 @@ static int lcurl_easy_unset_PROGRESSFUNCTION(lua_State *L){
615627 curl_easy_setopt (p -> curl , CURLOPT_XFERINFODATA , NULL );
616628#endif
617629
630+ luaL_unref (L , LCURL_LUA_REGISTRY , p -> pr .cb_ref );
631+ luaL_unref (L , LCURL_LUA_REGISTRY , p -> pr .ud_ref );
632+ p -> pr .cb_ref = p -> pr .ud_ref = LUA_NOREF ;
633+
618634 lua_settop (L , 1 );
619635 return 1 ;
620636}
@@ -642,6 +658,10 @@ static int lcurl_easy_unset_SEEKFUNCTION(lua_State *L){
642658 }
643659 curl_easy_setopt (p -> curl , CURLOPT_SEEKDATA , NULL );
644660
661+ luaL_unref (L , LCURL_LUA_REGISTRY , p -> seek .cb_ref );
662+ luaL_unref (L , LCURL_LUA_REGISTRY , p -> seek .ud_ref );
663+ p -> seek .cb_ref = p -> seek .ud_ref = LUA_NOREF ;
664+
645665 lua_settop (L , 1 );
646666 return 1 ;
647667}
@@ -655,6 +675,10 @@ static int lcurl_easy_unset_DEBUGFUNCTION(lua_State *L){
655675 }
656676 curl_easy_setopt (p -> curl , CURLOPT_DEBUGDATA , NULL );
657677
678+ luaL_unref (L , LCURL_LUA_REGISTRY , p -> debug .cb_ref );
679+ luaL_unref (L , LCURL_LUA_REGISTRY , p -> debug .ud_ref );
680+ p -> debug .cb_ref = p -> debug .ud_ref = LUA_NOREF ;
681+
658682 lua_settop (L , 1 );
659683 return 1 ;
660684}
@@ -670,6 +694,10 @@ static int lcurl_easy_unset_FNMATCH_FUNCTION(lua_State *L){
670694 }
671695 curl_easy_setopt (p -> curl , CURLOPT_FNMATCH_DATA , NULL );
672696
697+ luaL_unref (L , LCURL_LUA_REGISTRY , p -> match .cb_ref );
698+ luaL_unref (L , LCURL_LUA_REGISTRY , p -> match .ud_ref );
699+ p -> match .cb_ref = p -> match .ud_ref = LUA_NOREF ;
700+
673701 lua_settop (L , 1 );
674702 return 1 ;
675703}
@@ -681,7 +709,14 @@ static int lcurl_easy_unset_CHUNK_BGN_FUNCTION(lua_State *L){
681709 if (code != CURLE_OK ){
682710 return lcurl_fail_ex (L , p -> err_mode , LCURL_ERROR_EASY , code );
683711 }
684- // curl_easy_setopt(p->curl, CURLOPT_CHUNK_DATA, NULL);
712+ if (p -> chunk_end .cb_ref == LUA_NOREF ){
713+ // if other callback not set
714+ curl_easy_setopt (p -> curl , CURLOPT_CHUNK_DATA , NULL );
715+ }
716+
717+ luaL_unref (L , LCURL_LUA_REGISTRY , p -> chunk_bgn .cb_ref );
718+ luaL_unref (L , LCURL_LUA_REGISTRY , p -> chunk_bgn .ud_ref );
719+ p -> chunk_bgn .cb_ref = p -> chunk_bgn .ud_ref = LUA_NOREF ;
685720
686721 lua_settop (L , 1 );
687722 return 1 ;
@@ -693,7 +728,14 @@ static int lcurl_easy_unset_CHUNK_END_FUNCTION(lua_State *L){
693728 if (code != CURLE_OK ){
694729 return lcurl_fail_ex (L , p -> err_mode , LCURL_ERROR_EASY , code );
695730 }
696- // curl_easy_setopt(p->curl, CURLOPT_CHUNK_DATA, NULL);
731+ if (p -> chunk_bgn .cb_ref == LUA_NOREF ){
732+ // if other callback not set
733+ curl_easy_setopt (p -> curl , CURLOPT_CHUNK_DATA , NULL );
734+ }
735+
736+ luaL_unref (L , LCURL_LUA_REGISTRY , p -> chunk_end .cb_ref );
737+ luaL_unref (L , LCURL_LUA_REGISTRY , p -> chunk_end .ud_ref );
738+ p -> chunk_end .cb_ref = p -> chunk_end .ud_ref = LUA_NOREF ;
697739
698740 lua_settop (L , 1 );
699741 return 1 ;
0 commit comments