ast_variables_destroy(peer->chanvars);
peer->chanvars = NULL;
}
- if (peer->expire > -1)
- ast_sched_del(sched, peer->expire);
- if (peer->pokeexpire > -1)
- ast_sched_del(sched, peer->pokeexpire);
+ /* If the schedule delete fails, that means the schedule is currently
+ * running, which means we should wait for that thread to complete.
+ * Otherwise, there's a crashable race condition.
+ *
+ * NOTE: once peer is refcounted, this probably is no longer necessary.
+ */
+ while (peer->expire > -1 && ast_sched_del(sched, peer->expire))
+ usleep(1);
+ while (peer->pokeexpire > -1 && ast_sched_del(sched, peer->pokeexpire))
+ usleep(1);
+
register_peer_exten(peer, FALSE);
ast_free_ha(peer->ha);
if (peer->selfdestruct)
f->offset = AST_FRIENDLY_OFFSET;
f->src = pvt->t->name;
f->data = pvt->outbuf;
- return f;
+ /* We must clone the frame, because the pvt could disappear
+ * the moment after we return (and unlock the source channel).
+ */
+ return ast_frisolate(f);
}
static struct ast_frame *default_frameout(struct ast_trans_pvt *pvt)