@@ -98,6 +98,16 @@ bool network_data_set_endpoints (network_data *data, char *auth, char *check, ch
9898 return true;
9999}
100100
101+ void network_data_free (network_data * data , bool free_also_data ) {
102+ if (!data ) return ;
103+
104+ if (data -> authentication ) cloudsync_memory_free (data -> authentication );
105+ if (data -> check_endpoint ) cloudsync_memory_free (data -> check_endpoint );
106+ if (data -> upload_endpoint ) cloudsync_memory_free (data -> upload_endpoint );
107+ if (free_also_data ) cloudsync_memory_free (data );
108+ else memset (data , 0 , sizeof (network_data ));
109+ }
110+
101111// MARK: - Utils -
102112
103113#ifndef CLOUDSYNC_OMIT_CURL
@@ -611,25 +621,16 @@ void cloudsync_network_init (sqlite3_context *context, int argc, sqlite3_value *
611621 goto abort_cleanup ;
612622
613623abort_cleanup :
614- if (data ) {
615- if (data -> authentication ) cloudsync_memory_free (data -> authentication );
616- if (data -> check_endpoint ) cloudsync_memory_free (data -> check_endpoint );
617- if (data -> upload_endpoint ) cloudsync_memory_free (data -> upload_endpoint );
618- cloudsync_memory_free (data );
619- }
624+ network_data_free (data , true);
625+ cloudsync_set_auxdata (context , NULL );
620626}
621627
622628void cloudsync_network_cleanup (sqlite3_context * context , int argc , sqlite3_value * * argv ) {
623629 DEBUG_FUNCTION ("cloudsync_network_cleanup" );
624630
625631 network_data * data = (network_data * )cloudsync_get_auxdata (context );
626- if (data ) {
627- if (data -> authentication ) cloudsync_memory_free (data -> authentication );
628- if (data -> check_endpoint ) cloudsync_memory_free (data -> check_endpoint );
629- if (data -> upload_endpoint ) cloudsync_memory_free (data -> upload_endpoint );
630- cloudsync_memory_free (data );
631- }
632-
632+ cloudsync_set_auxdata (context , NULL );
633+ network_data_free (data , true);
633634 sqlite3_result_int (context , SQLITE_OK );
634635
635636 #ifndef CLOUDSYNC_OMIT_CURL
0 commit comments