Fix potential segfault in chan_sip
authorMark Spencer <markster@digium.com>
Mon, 31 Mar 2003 15:56:00 +0000 (15:56 +0000)
committerMark Spencer <markster@digium.com>
Mon, 31 Mar 2003 15:56:00 +0000 (15:56 +0000)
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@727 65c4cc65-6c06-0410-ace0-fbb531ad65f3

channels/chan_sip.c

index 882d3df..186fa42 100755 (executable)
@@ -362,14 +362,26 @@ static int retrans_pkt(void *data)
                                ast_queue_hangup(pkt->owner->owner, 1);
                        } else {
                                /* If no owner, destroy now */
+                               ast_pthread_mutex_unlock(&pkt->owner->lock);
                                sip_destroy(pkt->owner);
+                               pkt = NULL;
                        }
                }
        } else {
                /* Don't bother retransmitting.  It's about to be killed anyway */
                pkt->retransid = -1;
+               if (pkt->owner->owner) {
+                       /* XXX Potential deadlocK?? XXX */
+                       ast_queue_hangup(pkt->owner->owner, 1);
+               } else {
+                       /* If no owner, destroy now */
+                       ast_pthread_mutex_unlock(&pkt->owner->lock);
+                       sip_destroy(pkt->owner);
+                       pkt=NULL;
+               }
        }
-       ast_pthread_mutex_unlock(&pkt->owner->lock);
+       if (pkt)
+               ast_pthread_mutex_unlock(&pkt->owner->lock);
        return res;
 }
 
@@ -2179,7 +2191,7 @@ static int transmit_register(struct sip_registry *r, char *cmd, char *auth)
        char addr[80];
        struct sip_pvt *p;
        /* exit if we are already in process with this registrar ?*/
-       if ( (auth==NULL && r->regstate==REG_STATE_REGSENT) || r->regstate==REG_STATE_AUTHSENT) {
+       if ( r == NULL || (auth==NULL && r->regstate==REG_STATE_REGSENT) || r->regstate==REG_STATE_AUTHSENT) {
                ast_log(LOG_NOTICE, "Strange, trying to register when registration already pending\n");
                return 0;
        }