mirror of
https://git.tartarus.org/simon/putty.git
synced 2025-07-05 21:42:47 -05:00
Replace PktIn reference count with a 'free queue'.
This is a new idea I've had to make memory-management of PktIn even easier. The idea is that a PktIn is essentially _always_ an element of some linked-list queue: if it's not one of the queues by which packets move through ssh.c, then it's a special 'free queue' which holds packets that are unowned and due to be freed. pq_pop() on a PktInQueue automatically relinks the packet to the free queue, and also triggers an idempotent callback which will empty the queue and really free all the packets on it. Hence, you can pop a packet off a real queue, parse it, handle it, and then just assume it'll get tidied up at some point - the only constraint being that you have to finish with it before returning to the application's main loop. The exception is that it's OK to pq_push() the packet back on to some other PktInQueue, because a side effect of that will be to _remove_ it from the free queue again. (And if _all_ the incoming packets get that treatment, then when the free-queue handler eventually runs, it may find it has nothing to do - which is harmless.)
This commit is contained in:
6
ssh.c
6
ssh.c
@ -1043,7 +1043,6 @@ static void ssh_process_pq_full(void *ctx)
|
||||
if (ssh->general_packet_processing)
|
||||
ssh->general_packet_processing(ssh, pktin);
|
||||
ssh->packet_dispatch[pktin->type](ssh, pktin);
|
||||
ssh_unref_packet(pktin);
|
||||
}
|
||||
}
|
||||
|
||||
@ -3316,14 +3315,12 @@ static void ssh1_connection_input(Ssh ssh)
|
||||
|
||||
static void ssh1_coro_wrapper_initial(Ssh ssh, PktIn *pktin)
|
||||
{
|
||||
pktin->refcount++; /* avoid packet being freed when we return */
|
||||
pq_push(&ssh->pq_ssh1_login, pktin);
|
||||
queue_idempotent_callback(&ssh->ssh1_login_icb);
|
||||
}
|
||||
|
||||
static void ssh1_coro_wrapper_session(Ssh ssh, PktIn *pktin)
|
||||
{
|
||||
pktin->refcount++; /* avoid packet being freed when we return */
|
||||
pq_push(&ssh->pq_ssh1_connection, pktin);
|
||||
queue_idempotent_callback(&ssh->ssh1_connection_icb);
|
||||
}
|
||||
@ -6661,7 +6658,6 @@ static void ssh2_setup_env(struct ssh_channel *c, PktIn *pktin,
|
||||
*/
|
||||
static void ssh2_msg_userauth(Ssh ssh, PktIn *pktin)
|
||||
{
|
||||
pktin->refcount++; /* avoid packet being freed when we return */
|
||||
pq_push(&ssh->pq_ssh2_userauth, pktin);
|
||||
if (pktin->type == SSH2_MSG_USERAUTH_SUCCESS) {
|
||||
/*
|
||||
@ -8136,7 +8132,6 @@ static void ssh2_userauth_input(Ssh ssh)
|
||||
*/
|
||||
static void ssh2_msg_connection(Ssh ssh, PktIn *pktin)
|
||||
{
|
||||
pktin->refcount++; /* avoid packet being freed when we return */
|
||||
pq_push(&ssh->pq_ssh2_connection, pktin);
|
||||
queue_idempotent_callback(&ssh->ssh2_connection_icb);
|
||||
}
|
||||
@ -8610,7 +8605,6 @@ static void ssh2_msg_debug(Ssh ssh, PktIn *pktin)
|
||||
|
||||
static void ssh2_msg_transport(Ssh ssh, PktIn *pktin)
|
||||
{
|
||||
pktin->refcount++; /* avoid packet being freed when we return */
|
||||
pq_push(&ssh->pq_ssh2_transport, pktin);
|
||||
queue_idempotent_callback(&ssh->ssh2_transport_icb);
|
||||
}
|
||||
|
Reference in New Issue
Block a user