Skip to content

Commit 46eccee

Browse files
committed
Improved cloudsync_network_init
1 parent 77550bb commit 46eccee

2 files changed

Lines changed: 15 additions & 14 deletions

File tree

src/cloudsync.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
extern "C" {
2121
#endif
2222

23-
#define CLOUDSYNC_VERSION "0.8.60"
23+
#define CLOUDSYNC_VERSION "0.8.61"
2424

2525
int sqlite3_cloudsync_init (sqlite3 *db, char **pzErrMsg, const sqlite3_api_routines *pApi);
2626

src/network.c

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -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

613623
abort_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

622628
void 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

Comments
 (0)