From a7829044ecd75baa70b19d536f72ec4342f8485b Mon Sep 17 00:00:00 2001
From: Mark Michelson <mmichelson@digium.com>
Date: Wed, 17 Dec 2008 21:17:20 +0000
Subject: [PATCH] Merged revisions 165255 via svnmerge from
 https://origsvn.digium.com/svn/asterisk/branches/1.4

........
r165255 | mmichelson | 2008-12-17 14:51:38 -0600 (Wed, 17 Dec 2008) | 7 lines

Fix some memory leaks found while looking at how realtime
configs are handled.

Also cleaned up some coding guidelines violations in app_realtime.c,
mostly related to spacing


........


git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@165318 65c4cc65-6c06-0410-ace0-fbb531ad65f3
---
 apps/app_directory.c | 3 +++
 apps/app_meetme.c    | 6 ++++--
 apps/app_queue.c     | 6 +++++-
 apps/app_voicemail.c | 2 ++
 res/res_realtime.c   | 4 +++-
 5 files changed, 17 insertions(+), 4 deletions(-)

diff --git a/apps/app_directory.c b/apps/app_directory.c
index 2b0b6776cc..fe8139de5e 100644
--- a/apps/app_directory.c
+++ b/apps/app_directory.c
@@ -437,6 +437,9 @@ static struct ast_config *realtime_directory(char *context)
 			if (!(cat = ast_category_new(context, "", 99999))) {
 				ast_log(LOG_WARNING, "Out of memory\n");
 				ast_config_destroy(cfg);
+				if (rtdata) {
+					ast_config_destroy(rtdata);
+				}
 				return NULL;
 			}
 			ast_category_append(cfg, cat);
diff --git a/apps/app_meetme.c b/apps/app_meetme.c
index 025ad3561c..3ecd0a1396 100644
--- a/apps/app_meetme.c
+++ b/apps/app_meetme.c
@@ -1812,7 +1812,7 @@ static int rt_extend_conf(char *confno)
 	char endtime[32];
 	struct timeval now;
 	struct ast_tm tm;
-	struct ast_variable *var;
+	struct ast_variable *var, *orig_var;
 	char bookid[8]; 
 
 	if (!extendby) {
@@ -1828,6 +1828,8 @@ static int rt_extend_conf(char *confno)
 		confno, "startTime<= ", currenttime,
 		"endtime>= ", currenttime, NULL);
 
+	origvar = var;
+
 	/* Identify the specific RealTime conference */
 	while (var) {
 		if (!strcasecmp(var->name, "bookid")) {
@@ -1839,7 +1841,7 @@ static int rt_extend_conf(char *confno)
 
 		var = var->next;
 	}
-	ast_variables_destroy(var);
+	ast_variables_destroy(orig_var);
 
 	ast_strptime(endtime, DATE_FORMAT, &tm);
 	now = ast_mktime(&tm, NULL);
diff --git a/apps/app_queue.c b/apps/app_queue.c
index 07b7db1864..49276ebacd 100644
--- a/apps/app_queue.c
+++ b/apps/app_queue.c
@@ -2205,8 +2205,12 @@ static void leave_queue(struct queue_ent *qe)
 
 	/*If the queue is a realtime queue, check to see if it's still defined in real time*/
 	if (q->realtime) {
-		if (!ast_load_realtime("queues", "name", q->name, SENTINEL))
+		struct ast_variable *var;
+		if (!(var = ast_load_realtime("queues", "name", q->name, SENTINEL))) {
 			q->dead = 1;
+		} else {
+			ast_variables_destroy(var);
+		}
 	}
 
 	if (q->dead) {	
diff --git a/apps/app_voicemail.c b/apps/app_voicemail.c
index 92fc41d8b7..00693f11ba 100644
--- a/apps/app_voicemail.c
+++ b/apps/app_voicemail.c
@@ -9709,6 +9709,8 @@ static char *show_users_realtime(int fd, const char *context)
 		"=============================================================\n"
 		"\n");
 
+	ast_config_destroy(cfg);
+
 	return CLI_SUCCESS;
 }
 
diff --git a/res/res_realtime.c b/res/res_realtime.c
index ffc8c00958..9be076a6ba 100644
--- a/res/res_realtime.c
+++ b/res/res_realtime.c
@@ -43,7 +43,7 @@ ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
 static char *cli_realtime_load(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a) 
 {
 #define CRL_HEADER_FORMAT "%30s  %-30s\n"
-	struct ast_variable *var=NULL;
+	struct ast_variable *var = NULL, orig_var = NULL;
 
 	switch (cmd) {
 	case CLI_INIT:
@@ -66,6 +66,7 @@ static char *cli_realtime_load(struct ast_cli_entry *e, int cmd, struct ast_cli_
 	if (var) {
 		ast_cli(a->fd, CRL_HEADER_FORMAT, "Column Name", "Column Value");
 		ast_cli(a->fd, CRL_HEADER_FORMAT, "--------------------", "--------------------");
+		orig_var = var;
 		while (var) {
 			ast_cli(a->fd, CRL_HEADER_FORMAT, var->name, var->value);
 			var = var->next;
@@ -73,6 +74,7 @@ static char *cli_realtime_load(struct ast_cli_entry *e, int cmd, struct ast_cli_
 	} else {
 		ast_cli(a->fd, "No rows found matching search criteria.\n");
 	}
+	ast_variables_destroy(orig_var);
 	return CLI_SUCCESS;
 }
 
-- 
GitLab