Skip to content

Commit c55a268

Browse files
authored
Fix potential NPE when outbound fails to connect to a room. (#525)
1 parent 050eeba commit c55a268

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

pkg/sip/outbound.go

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -306,9 +306,10 @@ func (c *outboundCall) close(err error, status CallStatus, description string, r
306306
info.DisconnectReason = reason
307307
})
308308
c.media.Close()
309-
_ = c.lkRoom.CloseOutput()
310-
311-
_ = c.lkRoom.CloseWithReason(status.DisconnectReason())
309+
if r := c.lkRoom; r != nil {
310+
_ = r.CloseOutput()
311+
_ = r.CloseWithReason(status.DisconnectReason())
312+
}
312313
c.lkRoomIn = nil
313314

314315
c.stopSIP(description)
@@ -390,6 +391,7 @@ func (c *outboundCall) connectToRoom(ctx context.Context, lkNew RoomConfig, getR
390391
lkNew.Participant.Attributes = attrs
391392
r := getRoom(c.log, &c.stats.Room)
392393
if err := r.Connect(c.c.conf, lkNew); err != nil {
394+
_ = r.Close()
393395
return err
394396
}
395397
// We have to create the track early because we might play a dialtone while SIP connects.
@@ -492,6 +494,9 @@ func (c *outboundCall) setStatus(v CallStatus) {
492494
if attr == "" {
493495
return
494496
}
497+
if c.lkRoom == nil {
498+
return
499+
}
495500
r := c.lkRoom.Room()
496501
if r == nil {
497502
return
@@ -617,6 +622,9 @@ func (c *outboundCall) sipSignal(ctx context.Context, tid traceid.ID) error {
617622
}
618623

619624
func (c *outboundCall) handleDTMF(ev dtmf.Event) {
625+
if c.lkRoom == nil {
626+
return
627+
}
620628
_ = c.lkRoom.SendData(&livekit.SipDTMF{
621629
Code: uint32(ev.Code),
622630
Digit: string([]byte{ev.Digit}),

0 commit comments

Comments
 (0)