[asterisk-commits] russell: branch russell/cdr-q r248537 - /team/russell/cdr-q/main/cdr.c

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Wed Feb 24 01:15:49 CST 2010


Author: russell
Date: Wed Feb 24 01:15:45 2010
New Revision: 248537

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=248537
Log:
Plug some memory leaks on backend destruction

Modified:
    team/russell/cdr-q/main/cdr.c

Modified: team/russell/cdr-q/main/cdr.c
URL: http://svnview.digium.com/svn/asterisk/team/russell/cdr-q/main/cdr.c?view=diff&rev=248537&r1=248536&r2=248537
==============================================================================
--- team/russell/cdr-q/main/cdr.c (original)
+++ team/russell/cdr-q/main/cdr.c Wed Feb 24 01:15:45 2010
@@ -205,12 +205,86 @@
 	return ao2_find(cdr_backends, &tmp, OBJ_POINTER);
 }
 
+enum cdr_wrap_cache {
+	CDR_WRAP_CACHE,
+	CDR_WRAP_NO_CACHE,
+};
+
+/*!
+ * \internal
+ * \pre backend is locked
+ */
+static void release_cdr_wrap(struct ast_cdr_backend *backend, struct cdr_wrap *wrap,
+		enum cdr_wrap_cache cache)
+{
+	ao2_t_ref(wrap->cdr, -1, "Releasing CDR wrap ref");
+	wrap->cdr = NULL;
+
+	if (cache == CDR_WRAP_CACHE &&
+			ao2_container_count(backend->cdr_wrap_cache) < WRAP_CACHE_SIZE_MAX) {
+		ao2_link(backend->cdr_wrap_cache, wrap);
+	}
+
+	ao2_t_ref(wrap, -1, "releasing cdr wrapper");
+}
+
+/*!
+ * \internal
+ * \pre backend is locked
+ */
+static struct cdr_wrap *cdr_backend_dequeue(struct ast_cdr_backend *backend)
+{
+	if (AST_LIST_EMPTY(&backend->cdr_q)) {
+		return NULL;
+	}
+
+	backend->cdr_q_len--;
+
+	return AST_LIST_REMOVE_HEAD(&backend->cdr_q, entry);
+}
+
+enum cdr_backend_queue {
+	QUEUE_HEAD,
+	QUEUE_TAIL,
+};
+
+/*!
+ * \internal
+ * \pre backend is locked
+ */
+static void cdr_backend_queue(struct ast_cdr_backend *backend, struct cdr_wrap *wrap,
+		enum cdr_backend_queue location)
+{
+	backend->cdr_q_len++;
+
+	switch (location) {
+	case QUEUE_HEAD:
+		AST_LIST_INSERT_HEAD(&backend->cdr_q, wrap, entry);
+		break;
+	case QUEUE_TAIL:
+		AST_LIST_INSERT_TAIL(&backend->cdr_q, wrap, entry);
+		break;
+	}
+}
+
 static void cdr_backend_destructor(void *obj)
 {
 	struct ast_cdr_backend *backend = obj;
 
 	if (backend->tps) {
 		backend->tps = ast_taskprocessor_unreference(backend->tps);
+	}
+
+	if (backend->cdr_q_len) {
+		struct cdr_wrap *wrap;
+
+		ast_log(LOG_ERROR, "Destroying backend '%s%s%s with %d CDR records not logged.\n",
+				backend->name, ast_strlen_zero(backend->unique_id) ? "" : "-",
+				S_OR(backend->unique_id, ""), backend->cdr_q_len);
+
+		while ((wrap = cdr_backend_dequeue(backend))) {
+			release_cdr_wrap(backend, wrap, CDR_WRAP_NO_CACHE);
+		}
 	}
 
 	if (backend->cdr_wrap_cache) {
@@ -1386,61 +1460,6 @@
 	return -1;
 }
 
-/*!
- * \internal
- * \pre backend is locked
- */
-static void release_cdr_wrap(struct ast_cdr_backend *backend, struct cdr_wrap *wrap)
-{
-	ao2_t_ref(wrap->cdr, -1, "Releasing CDR wrap ref");
-	wrap->cdr = NULL;
-
-	if (ao2_container_count(backend->cdr_wrap_cache) < WRAP_CACHE_SIZE_MAX) {
-		ao2_link(backend->cdr_wrap_cache, wrap);
-	}
-
-	ao2_t_ref(wrap, -1, "releasing cdr wrapper");
-}
-
-/*!
- * \internal
- * \pre backend is locked
- */
-static struct cdr_wrap *cdr_backend_dequeue(struct ast_cdr_backend *backend)
-{
-	if (AST_LIST_EMPTY(&backend->cdr_q)) {
-		return NULL;
-	}
-
-	backend->cdr_q_len--;
-
-	return AST_LIST_REMOVE_HEAD(&backend->cdr_q, entry);
-}
-
-enum cdr_backend_queue {
-	QUEUE_HEAD,
-	QUEUE_TAIL,
-};
-
-/*!
- * \internal
- * \pre backend is locked
- */
-static void cdr_backend_queue(struct ast_cdr_backend *backend, struct cdr_wrap *wrap,
-		enum cdr_backend_queue location)
-{
-	backend->cdr_q_len++;
-
-	switch (location) {
-	case QUEUE_HEAD:
-		AST_LIST_INSERT_HEAD(&backend->cdr_q, wrap, entry);
-		break;
-	case QUEUE_TAIL:
-		AST_LIST_INSERT_TAIL(&backend->cdr_q, wrap, entry);
-		break;
-	}
-}
-
 static int flush_cdr_q(void *arg)
 {
 	struct ast_cdr_backend *backend = arg;
@@ -1474,7 +1493,7 @@
 				backend->last_error = now;
 			}
 		} else {
-			release_cdr_wrap(backend, wrap);
+			release_cdr_wrap(backend, wrap, CDR_WRAP_CACHE);
 		}
 	}
 	ao2_unlock(backend);




More information about the asterisk-commits mailing list