MINOR: conn-stream: Use a dedicated function to conditionally remove a CS

cs_free_cond() must now be used to remove a CS. cs_free() may be used on
error path to release a freshly allocated but unused CS. But in all other
cases cs_free_cond() must be used. This function takes care to release the
CS if it is possible (no app and detached from any endpoint).

In fact, this function is only used internally. From the outside,
cs_detach_* functions are used.
This commit is contained in:
Christopher Faulet 2022-04-12 18:09:48 +02:00
parent a97ccedf6f
commit aa69d8fa1c
1 changed files with 11 additions and 6 deletions

View File

@ -244,6 +244,15 @@ void cs_free(struct conn_stream *cs)
pool_free(pool_head_connstream, cs);
}
/* Conditionally removes a conn-stream if it is detached and it there is no app
* layer defined. Except on error path, this one must be used.
*/
static void cs_free_cond(struct conn_stream *cs)
{
if (!cs->app && (!cs->endp || (cs->endp->flags & CS_EP_DETACHED)))
cs_free(cs);
}
/* Attaches a conn_stream to a mux endpoint and sets the endpoint ctx. Returns
* -1 on error and 0 on sucess. CS_EP_DETACHED flag is removed. This function is
@ -385,9 +394,7 @@ void cs_detach_endp(struct conn_stream *cs)
if (cs_strm(cs))
cs->ops = &cs_app_embedded_ops;
cs->data_cb = NULL;
if (cs->app == NULL)
cs_free(cs);
cs_free_cond(cs);
}
/* Detaches the conn_stream from the app layer. If there is no endpoint attached
@ -404,9 +411,7 @@ void cs_detach_app(struct conn_stream *cs)
tasklet_free(cs->wait_event.tasklet);
cs->wait_event.tasklet = NULL;
cs->wait_event.events = 0;
if (!cs->endp || (cs->endp->flags & CS_EP_DETACHED))
cs_free(cs);
cs_free_cond(cs);
}
/* Resets the conn-stream endpoint. It happens when the app layer want to renew