[Asterisk-code-review] res calendar: delete old calendars after reload (asterisk[master])

Martin Tomec asteriskteam at digium.com
Fri Dec 30 07:33:40 CST 2016


Martin Tomec has uploaded a new change for review. ( https://gerrit.asterisk.org/4683 )

Change subject: res_calendar: delete old calendars after reload
......................................................................

res_calendar: delete old calendars after reload

When "fetch_again_at_reload" is set in config, we create now
new object and thread for each reloaded calendar (with new
configuration). Old calendar should be then unlinked, so the
old thread can exit and free memory.

ASTERISK-26683

Change-Id: Ic17fba9371c5a8b26a6bc54ea4957c13a32a343e
---
M res/res_calendar.c
1 file changed, 8 insertions(+), 2 deletions(-)


  git pull ssh://gerrit.asterisk.org:29418/asterisk refs/changes/83/4683/1

diff --git a/res/res_calendar.c b/res/res_calendar.c
index 4677550..cfcd8bf 100644
--- a/res/res_calendar.c
+++ b/res/res_calendar.c
@@ -406,7 +406,13 @@
 	struct ast_variable *v, *last = NULL;
 	int new_calendar = 0;
 
-	if (!(cal = find_calendar(cat))) {
+	cal = find_calendar(cat);
+	if (cal && cal->fetch_again_at_reload) {
+		/** remove old calendar. New will be created */
+		cal->pending_deletion = 1;
+		cal = unref_calendar(cal);
+	}
+	if (!cal) {
 		new_calendar = 1;
 		if (!(cal = ao2_alloc(sizeof(*cal), calendar_destructor))) {
 			ast_log(LOG_ERROR, "Could not allocate calendar structure. Stopping.\n");
@@ -483,7 +489,7 @@
 		}
 	}
 
-	if (new_calendar || cal->fetch_again_at_reload) {
+	if (new_calendar) {
 		cal->thread = AST_PTHREADT_NULL;
 		ast_cond_init(&cal->unload, NULL);
 		ao2_link(calendars, cal);

-- 
To view, visit https://gerrit.asterisk.org/4683
To unsubscribe, visit https://gerrit.asterisk.org/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: Ic17fba9371c5a8b26a6bc54ea4957c13a32a343e
Gerrit-PatchSet: 1
Gerrit-Project: asterisk
Gerrit-Branch: master
Gerrit-Owner: Martin Tomec <tomec.martin at gmail.com>



More information about the asterisk-code-review mailing list