@@ -674,7 +674,7 @@ static Tox *tox_new_system(const struct Tox_Options *_Nullable options, Tox_Err_
674674 const Network * const ns = sys -> ns ;
675675 const Memory * const mem = sys -> mem ;
676676
677- Messenger_Options m_options = {false };
677+ Messenger_Options m_options = {nullptr };
678678
679679 m_options .dns_enabled = !tox_options_get_experimental_disable_dns (opts );
680680
@@ -736,9 +736,21 @@ static Tox *tox_new_system(const struct Tox_Options *_Nullable options, Tox_Err_
736736 }
737737
738738 tox -> log_callback = tox_options_get_log_callback (opts );
739- m_options .log_callback = tox_log_handler ;
740- m_options .log_context = tox ;
741- m_options .log_user_data = tox_options_get_log_user_data (opts );
739+
740+ Logger * log = logger_new (mem );
741+
742+ if (log == nullptr ) {
743+ SET_ERROR_PARAMETER (error , TOX_ERR_NEW_MALLOC );
744+ mem_delete (mem , tox );
745+ tox_options_free (default_options );
746+ return nullptr ;
747+ }
748+
749+ tox -> log = log ;
750+
751+ m_options .log = tox -> log ;
752+
753+ logger_callback_log (tox -> log , tox_log_handler , tox , tox_options_get_log_user_data (opts ));
742754
743755 switch (tox_options_get_proxy_type (opts )) {
744756 case TOX_PROXY_TYPE_HTTP : {
@@ -758,6 +770,7 @@ static Tox *tox_new_system(const struct Tox_Options *_Nullable options, Tox_Err_
758770
759771 default : {
760772 SET_ERROR_PARAMETER (error , TOX_ERR_NEW_PROXY_BAD_TYPE );
773+ logger_kill (tox -> log );
761774 mem_delete (mem , tox );
762775 tox_options_free (default_options );
763776 return nullptr ;
@@ -769,6 +782,7 @@ static Tox *tox_new_system(const struct Tox_Options *_Nullable options, Tox_Err_
769782 if (m_options .proxy_info .proxy_type != TCP_PROXY_NONE ) {
770783 if (tox_options_get_proxy_port (opts ) == 0 ) {
771784 SET_ERROR_PARAMETER (error , TOX_ERR_NEW_PROXY_BAD_PORT );
785+ logger_kill (tox -> log );
772786 mem_delete (mem , tox );
773787 tox_options_free (default_options );
774788 return nullptr ;
@@ -787,6 +801,7 @@ static Tox *tox_new_system(const struct Tox_Options *_Nullable options, Tox_Err_
787801 || !addr_resolve_or_parse_ip (ns , mem , proxy_host , & m_options .proxy_info .ip_port .ip , nullptr , dns_enabled )) {
788802 SET_ERROR_PARAMETER (error , TOX_ERR_NEW_PROXY_BAD_HOST );
789803 // TODO(irungentoo): TOX_ERR_NEW_PROXY_NOT_FOUND if domain.
804+ logger_kill (tox -> log );
790805 mem_delete (mem , tox );
791806 tox_options_free (default_options );
792807 return nullptr ;
@@ -799,6 +814,7 @@ static Tox *tox_new_system(const struct Tox_Options *_Nullable options, Tox_Err_
799814
800815 if (temp_mono_time == nullptr ) {
801816 SET_ERROR_PARAMETER (error , TOX_ERR_NEW_MALLOC );
817+ logger_kill (tox -> log );
802818 mem_delete (mem , tox );
803819 tox_options_free (default_options );
804820 return nullptr ;
@@ -810,6 +826,8 @@ static Tox *tox_new_system(const struct Tox_Options *_Nullable options, Tox_Err_
810826
811827 if (mutex == nullptr ) {
812828 SET_ERROR_PARAMETER (error , TOX_ERR_NEW_MALLOC );
829+ mono_time_free (mem , tox -> mono_time );
830+ logger_kill (tox -> log );
813831 mem_delete (mem , tox );
814832 tox_options_free (default_options );
815833 return nullptr ;
@@ -849,6 +867,7 @@ static Tox *tox_new_system(const struct Tox_Options *_Nullable options, Tox_Err_
849867 }
850868
851869 mem_delete (mem , tox -> mutex );
870+ logger_kill (tox -> log );
852871 mem_delete (mem , tox );
853872 tox_options_free (default_options );
854873 return nullptr ;
@@ -868,6 +887,7 @@ static Tox *tox_new_system(const struct Tox_Options *_Nullable options, Tox_Err_
868887 }
869888
870889 mem_delete (mem , tox -> mutex );
890+ logger_kill (tox -> log );
871891 mem_delete (mem , tox );
872892
873893 SET_ERROR_PARAMETER (error , TOX_ERR_NEW_MALLOC );
@@ -888,6 +908,7 @@ static Tox *tox_new_system(const struct Tox_Options *_Nullable options, Tox_Err_
888908 }
889909
890910 mem_delete (mem , tox -> mutex );
911+ logger_kill (tox -> log );
891912 mem_delete (mem , tox );
892913
893914 SET_ERROR_PARAMETER (error , TOX_ERR_NEW_LOAD_BAD_FORMAT );
@@ -990,6 +1011,7 @@ void tox_kill(Tox *tox)
9901011 LOGGER_ASSERT (tox -> m -> log , tox -> toxav_object == nullptr , "Attempted to kill tox while toxav is still alive" );
9911012 kill_groupchats (tox -> m -> conferences_object );
9921013 kill_messenger (tox -> m );
1014+ logger_kill (tox -> log );
9931015 mono_time_free (tox -> sys .mem , tox -> mono_time );
9941016 tox_unlock (tox );
9951017
0 commit comments