Language: C
Label: safe
CWE: CWE-416 \u2014 Use After Free
Referencing memory after it has been freed can cause a program to crash, use unexpected values, or execute code.

Code:
static pj_status_t dtls_destroy(pjmedia_transport *tp)
{
    dtls_srtp *ds = (dtls_srtp *)tp;

#if DTLS_DEBUG
    PJ_LOG(2,(ds->base.name, "dtls_destroy()"));
#endif

    ds->is_destroying = PJ_TRUE;

    DTLS_LOCK(ds);

    dtls_destroy_channel(ds, RTP_CHANNEL);
    dtls_destroy_channel(ds, RTCP_CHANNEL);

    DTLS_UNLOCK(ds);

    if (ds->base.grp_lock) {
        pj_grp_lock_dec_ref(ds->base.grp_lock);
    } else {
        dtls_on_destroy(tp);
    }

    return PJ_SUCCESS;
}