Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cleanup: Make *_free and kill_* functions nullable. #2238

Merged
merged 1 commit into from
Apr 2, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion other/bootstrap_daemon/docker/tox-bootstrapd.sha256
Original file line number Diff line number Diff line change
@@ -1 +1 @@
ffa04330027fd3d29e395f4609107e685d4cc7ca58caa2d24ebdb9569c0c855a /usr/local/bin/tox-bootstrapd
eba633bbca47d051b4b23e5ae14537a6d872a50aa0da8b7635214ee6908b87db /usr/local/bin/tox-bootstrapd
4 changes: 4 additions & 0 deletions toxcore/DHT.c
Original file line number Diff line number Diff line change
Expand Up @@ -2655,6 +2655,10 @@ void do_dht(DHT *dht)

void kill_dht(DHT *dht)
{
if (dht == nullptr) {
return;
}

networking_registerhandler(dht->net, NET_PACKET_GET_NODES, nullptr, nullptr);
networking_registerhandler(dht->net, NET_PACKET_SEND_NODES_IPV6, nullptr, nullptr);
networking_registerhandler(dht->net, NET_PACKET_CRYPTO, nullptr, nullptr);
Expand Down
2 changes: 1 addition & 1 deletion toxcore/DHT.h
Original file line number Diff line number Diff line change
Expand Up @@ -473,7 +473,7 @@ non_null()
DHT *new_dht(const Logger *log, const Random *rng, const Network *ns, Mono_Time *mono_time, Networking_Core *net,
bool hole_punching_enabled, bool lan_discovery_enabled);

non_null()
nullable(1)
void kill_dht(DHT *dht);

/**
Expand Down
2 changes: 1 addition & 1 deletion toxcore/Messenger.h
Original file line number Diff line number Diff line change
Expand Up @@ -761,7 +761,7 @@ Messenger *new_messenger(Mono_Time *mono_time, const Random *rng, const Network
*
* Free all datastructures.
*/
non_null()
nullable(1)
void kill_messenger(Messenger *m);

/** @brief The main loop that needs to be run at least 20 times per second. */
Expand Down
4 changes: 4 additions & 0 deletions toxcore/TCP_connection.c
Original file line number Diff line number Diff line change
Expand Up @@ -1580,6 +1580,10 @@ void do_tcp_connections(const Logger *logger, TCP_Connections *tcp_c, void *user

void kill_tcp_connections(TCP_Connections *tcp_c)
{
if (tcp_c == nullptr) {
return;
}

for (uint32_t i = 0; i < tcp_c->tcp_connections_length; ++i) {
kill_TCP_connection(tcp_c->tcp_connections[i].connection);
}
Expand Down
3 changes: 2 additions & 1 deletion toxcore/TCP_connection.h
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,8 @@ int kill_tcp_relay_connection(TCP_Connections *tcp_c, int tcp_connections_number

non_null(1, 2) nullable(3)
void do_tcp_connections(const Logger *logger, TCP_Connections *tcp_c, void *userdata);
non_null()

nullable(1)
void kill_tcp_connections(TCP_Connections *tcp_c);

#endif
4 changes: 4 additions & 0 deletions toxcore/TCP_server.c
Original file line number Diff line number Diff line change
Expand Up @@ -1277,6 +1277,10 @@ void do_TCP_server(TCP_Server *tcp_server, const Mono_Time *mono_time)

void kill_TCP_server(TCP_Server *tcp_server)
{
if (tcp_server == nullptr) {
return;
}

for (uint32_t i = 0; i < tcp_server->num_listening_socks; ++i) {
kill_sock(tcp_server->ns, tcp_server->socks_listening[i]);
}
Expand Down
2 changes: 1 addition & 1 deletion toxcore/TCP_server.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ non_null()
void do_TCP_server(TCP_Server *tcp_server, const Mono_Time *mono_time);

/** Kill the TCP server */
non_null()
nullable(1)
void kill_TCP_server(TCP_Server *tcp_server);


Expand Down
2 changes: 1 addition & 1 deletion toxcore/bin_pack.h
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ Bin_Pack *bin_pack_new(uint8_t *buf, uint32_t buf_size);
*
* Does not deallocate the buffer inside.
*/
non_null()
nullable(1)
void bin_pack_free(Bin_Pack *bp);

/** @brief Start packing a MessagePack array.
Expand Down
2 changes: 1 addition & 1 deletion toxcore/friend_connection.h
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ non_null()
void do_friend_connections(Friend_Connections *fr_c, void *userdata);

/** Free everything related with friend_connections. */
non_null()
nullable(1)
void kill_friend_connections(Friend_Connections *fr_c);

typedef struct Friend_Conn Friend_Conn;
Expand Down
4 changes: 3 additions & 1 deletion toxcore/friend_requests.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ non_null()
void friendreq_init(Friend_Requests *fr, Friend_Connections *fr_c);

Friend_Requests *friendreq_new(void);
non_null() void friendreq_kill(Friend_Requests *fr);

nullable(1)
void friendreq_kill(Friend_Requests *fr);

#endif
4 changes: 4 additions & 0 deletions toxcore/group.c
Original file line number Diff line number Diff line change
Expand Up @@ -3800,6 +3800,10 @@ void do_groupchats(Group_Chats *g_c, void *userdata)
/** Free everything related with group chats. */
void kill_groupchats(Group_Chats *g_c)
{
if (g_c == nullptr) {
return;
}

for (uint16_t i = 0; i < g_c->num_chats; ++i) {
del_groupchat(g_c, i, false);
}
Expand Down
2 changes: 1 addition & 1 deletion toxcore/group.h
Original file line number Diff line number Diff line change
Expand Up @@ -392,7 +392,7 @@ non_null(1) nullable(2)
void do_groupchats(Group_Chats *g_c, void *userdata);

/** Free everything related with group chats. */
non_null()
nullable(1)
void kill_groupchats(Group_Chats *g_c);

#endif
4 changes: 4 additions & 0 deletions toxcore/list.c
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,10 @@ int bs_list_init(BS_List *list, uint32_t element_size, uint32_t initial_capacity

void bs_list_free(BS_List *list)
{
if (list == nullptr) {
return;
}

// free both arrays
free(list->data);
list->data = nullptr;
Expand Down
2 changes: 1 addition & 1 deletion toxcore/list.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ non_null()
int bs_list_init(BS_List *list, uint32_t element_size, uint32_t initial_capacity);

/** Free a list initiated with list_init */
non_null()
nullable(1)
void bs_list_free(BS_List *list);

/** @brief Retrieve the id of an element in the list
Expand Down
2 changes: 1 addition & 1 deletion toxcore/logger.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ Logger *logger_new(void);
/**
* Frees all resources associated with the logger.
*/
non_null()
nullable(1)
void logger_kill(Logger *log);

/**
Expand Down
3 changes: 3 additions & 0 deletions toxcore/mono_time.c
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,9 @@ Mono_Time *mono_time_new(void)

void mono_time_free(Mono_Time *mono_time)
{
if (mono_time == nullptr) {
return;
}
#ifdef OS_WIN32
pthread_mutex_destroy(&mono_time->last_clock_lock);
#endif
Expand Down
4 changes: 3 additions & 1 deletion toxcore/mono_time.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,9 @@ extern "C" {
typedef struct Mono_Time Mono_Time;

Mono_Time *mono_time_new(void);
non_null() void mono_time_free(Mono_Time *mono_time);

nullable(1)
void mono_time_free(Mono_Time *mono_time);

/**
* Update mono_time; subsequent calls to mono_time_get or mono_time_is_timeout
Expand Down
4 changes: 4 additions & 0 deletions toxcore/net_crypto.c
Original file line number Diff line number Diff line change
Expand Up @@ -3172,6 +3172,10 @@ void do_net_crypto(Net_Crypto *c, void *userdata)

void kill_net_crypto(Net_Crypto *c)
{
if (c == nullptr) {
return;
}

for (uint32_t i = 0; i < c->crypto_connections_length; ++i) {
crypto_kill(c, i);
}
Expand Down
3 changes: 2 additions & 1 deletion toxcore/net_crypto.h
Original file line number Diff line number Diff line change
Expand Up @@ -386,6 +386,7 @@ uint32_t crypto_run_interval(const Net_Crypto *c);
non_null(1) nullable(2)
void do_net_crypto(Net_Crypto *c, void *userdata);

non_null() void kill_net_crypto(Net_Crypto *c);
nullable(1)
void kill_net_crypto(Net_Crypto *c);

#endif
2 changes: 1 addition & 1 deletion toxcore/network.h
Original file line number Diff line number Diff line change
Expand Up @@ -579,7 +579,7 @@ non_null()
Networking_Core *new_networking_no_udp(const Logger *log, const Network *ns);

/** Function to cleanup networking stuff (doesn't do much right now). */
non_null()
nullable(1)
void kill_networking(Networking_Core *net);

#ifdef __cplusplus
Expand Down
2 changes: 1 addition & 1 deletion toxcore/onion.h
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ void set_callback_handle_recv_1(Onion *onion, onion_recv_1_cb *function, void *o
non_null()
Onion *new_onion(const Logger *log, const Mono_Time *mono_time, const Random *rng, DHT *dht);

non_null()
nullable(1)
void kill_onion(Onion *onion);


Expand Down
2 changes: 1 addition & 1 deletion toxcore/onion_announce.h
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ void onion_announce_extra_data_callback(Onion_Announce *onion_a, uint16_t extra_
non_null()
Onion_Announce *new_onion_announce(const Logger *log, const Random *rng, const Mono_Time *mono_time, DHT *dht);

non_null()
nullable(1)
void kill_onion_announce(Onion_Announce *onion_a);

#endif
2 changes: 1 addition & 1 deletion toxcore/onion_client.h
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ void do_onion_client(Onion_Client *onion_c);
non_null()
Onion_Client *new_onion_client(const Logger *logger, const Random *rng, const Mono_Time *mono_time, Net_Crypto *c);

non_null()
nullable(1)
void kill_onion_client(Onion_Client *onion_c);


Expand Down
2 changes: 1 addition & 1 deletion toxcore/ping.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ typedef struct Ping Ping;
non_null()
Ping *ping_new(const Mono_Time *mono_time, const Random *rng, DHT *dht);

non_null()
nullable(1)
void ping_kill(Ping *ping);

/** @brief Add nodes to the to_ping list.
Expand Down
2 changes: 1 addition & 1 deletion toxcore/ping_array.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ struct Ping_Array *ping_array_new(uint32_t size, uint32_t timeout);
/**
* @brief Free all the allocated memory in a @ref Ping_Array.
*/
non_null()
nullable(1)
void ping_array_kill(Ping_Array *array);

/**
Expand Down