mirror of
https://github.com/irungentoo/toxcore.git
synced 2024-03-22 13:30:51 +08:00
Fixed crash when connection was killed during the packet callback.
This commit is contained in:
parent
4eeeb8e9ab
commit
d7f5713277
|
@ -274,6 +274,11 @@ static int handle_packet(void *object, int number, uint8_t *data, uint16_t lengt
|
|||
if (friend_con->callbacks[i].data_callback)
|
||||
friend_con->callbacks[i].data_callback(friend_con->callbacks[i].data_callback_object,
|
||||
friend_con->callbacks[i].data_callback_id, data, length);
|
||||
|
||||
friend_con = get_conn(fr_c, number);
|
||||
|
||||
if (!friend_con)
|
||||
return -1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
@ -296,6 +301,11 @@ static int handle_lossy_packet(void *object, int number, const uint8_t *data, ui
|
|||
if (friend_con->callbacks[i].lossy_data_callback)
|
||||
friend_con->callbacks[i].lossy_data_callback(friend_con->callbacks[i].lossy_data_callback_object,
|
||||
friend_con->callbacks[i].lossy_data_callback_id, data, length);
|
||||
|
||||
friend_con = get_conn(fr_c, number);
|
||||
|
||||
if (!friend_con)
|
||||
return -1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
|
|
@ -1180,6 +1180,12 @@ static int handle_data_packet_helper(const Net_Crypto *c, int crypt_connection_i
|
|||
if (conn->connection_data_callback)
|
||||
conn->connection_data_callback(conn->connection_data_callback_object, conn->connection_data_callback_id, dt.data,
|
||||
dt.length);
|
||||
|
||||
/* conn might get killed in callback. */
|
||||
conn = get_crypto_connection(c, crypt_connection_id);
|
||||
|
||||
if (conn == 0)
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* Packet counter. */
|
||||
|
@ -1187,11 +1193,12 @@ static int handle_data_packet_helper(const Net_Crypto *c, int crypt_connection_i
|
|||
} else if (real_data[0] >= PACKET_ID_LOSSY_RANGE_START &&
|
||||
real_data[0] < (PACKET_ID_LOSSY_RANGE_START + PACKET_ID_LOSSY_RANGE_SIZE)) {
|
||||
|
||||
set_buffer_end(&conn->recv_array, num);
|
||||
|
||||
if (conn->connection_lossy_data_callback)
|
||||
conn->connection_lossy_data_callback(conn->connection_lossy_data_callback_object,
|
||||
conn->connection_lossy_data_callback_id, real_data, real_length);
|
||||
|
||||
set_buffer_end(&conn->recv_array, num);
|
||||
} else {
|
||||
return -1;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user