[asterisk-commits] branch bweschke/bug_6047 - r8224 /team/bweschke/bug_6047/channels/chan_sip.c

asterisk-commits at lists.digium.com asterisk-commits at lists.digium.com
Wed Jan 18 20:25:59 MST 2006


Author: bweschke
Date: Wed Jan 18 21:25:57 2006
New Revision: 8224

URL: http://svn.digium.com/view/asterisk?rev=8224&view=rev
Log:
 Better memory managment routine on unload chan_sip.so 


Modified:
    team/bweschke/bug_6047/channels/chan_sip.c

Modified: team/bweschke/bug_6047/channels/chan_sip.c
URL: http://svn.digium.com/view/asterisk/team/bweschke/bug_6047/channels/chan_sip.c?rev=8224&r1=8223&r2=8224&view=diff
==============================================================================
--- team/bweschke/bug_6047/channels/chan_sip.c (original)
+++ team/bweschke/bug_6047/channels/chan_sip.c Wed Jan 18 21:25:57 2006
@@ -522,6 +522,34 @@
 	char *context;                  /*!< Context the hint is for */
 	char *exten;                    /*!< Extension the hint is for */
 	struct sip_pvt *p;              /*!< SIP Session Structure Ptr */
+};
+
+struct sched {
+	struct sched *next;             /* Next event in the list */
+	int id;                         /* ID number of event */
+	struct timeval when;            /* Absolute time event should take place */
+	int resched;                    /* When to reschedule */
+	int variable;                   /* Use return value from callback to reschedule */
+	void *data;                     /* Data */
+	ast_sched_cb callback;          /* Callback */
+};
+
+struct sched_context {
+	ast_mutex_t lock;
+	/* Number of events processed */
+	int eventcnt;
+
+	/* Number of outstanding schedule events */
+	int schedcnt;
+
+	/* Schedule entry and main queue */
+	struct sched *schedq;
+
+#ifdef SCHED_MAX_CACHE
+	/* Cache of unused schedule structures and how many */
+	struct sched *schedc;
+	int schedccnt;
+#endif
 };
 
 #define SIP_ALREADYGONE		(1 << 0)	/*!< Whether or not we've already been destroyed by our peer */
@@ -13128,6 +13156,34 @@
 	return 0;
 }
 
+static void sip_sched_context_destroy(struct sched_context *con)
+{
+        struct sched *s, *sl;
+        ast_mutex_lock(&con->lock);
+#ifdef SCHED_MAX_CACHE
+        /* And the queue */
+        s = con->schedc;
+        while(s) {
+                sl = s;
+		if (sl->callback == cb_hintmanager)
+			free(sl->data);
+                s = s->next;
+        }
+#endif
+        /* And the queue */
+        s = con->schedq;
+        while(s) {
+                sl = s;
+		if (sl->callback == cb_hintmanager)
+			free(sl->data);
+                s = s->next;
+        }
+        /* And the context */
+        ast_mutex_unlock(&con->lock);
+        ast_mutex_destroy(&con->lock);
+	sched_context_destroy(con);
+}
+
 int unload_module()
 {
 	struct sip_pvt *p, *pl;
@@ -13197,6 +13253,7 @@
 		return -1;
 	}
 
+
 	/* Free memory for local network address mask */
 	ast_free_ha(localaddr);
 
@@ -13211,6 +13268,9 @@
 	clear_sip_domains();
 	close(sipsock);
 		
+	/* Tear down and cleanup the scheduler context */
+	sip_sched_context_destroy(sched);
+
 	return 0;
 }
 



More information about the asterisk-commits mailing list