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

Anonymous Coward asteriskteam at digium.com
Tue Jan 17 18:44:02 CST 2017


Anonymous Coward #1000019 has submitted this change and it was merged. ( 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, 7 insertions(+), 2 deletions(-)

Approvals:
  Kevin Harwell: Looks good to me, approved
  Anonymous Coward #1000019: Verified
  Joshua Colp: Looks good to me, but someone else must approve



diff --git a/res/res_calendar.c b/res/res_calendar.c
index 4677550..92b73c1 100644
--- a/res/res_calendar.c
+++ b/res/res_calendar.c
@@ -406,7 +406,12 @@
 	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) {
+		/** Create new calendar, old will be removed during reload */
+		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 +488,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: merged
Gerrit-Change-Id: Ic17fba9371c5a8b26a6bc54ea4957c13a32a343e
Gerrit-PatchSet: 2
Gerrit-Project: asterisk
Gerrit-Branch: master
Gerrit-Owner: Martin Tomec <tomec.martin at gmail.com>
Gerrit-Reviewer: Anonymous Coward #1000019
Gerrit-Reviewer: Joshua Colp <jcolp at digium.com>
Gerrit-Reviewer: Kevin Harwell <kharwell at digium.com>
Gerrit-Reviewer: Mark Michelson <mmichelson at digium.com>
Gerrit-Reviewer: Martin Tomec <tomec.martin at gmail.com>



More information about the asterisk-code-review mailing list