[Asterisk-cvs] asterisk/res res_musiconhold.c,1.39.2.3,1.39.2.4

russell russell
Thu Aug 4 19:41:51 CDT 2005


Update of /usr/cvsroot/asterisk/res
In directory mongoose.digium.com:/tmp/cvs-serv3795/res

Modified Files:
      Tag: v1-0
	res_musiconhold.c 
Log Message:
prevent mem leak (bug #4842)


Index: res_musiconhold.c
===================================================================
RCS file: /usr/cvsroot/asterisk/res/res_musiconhold.c,v
retrieving revision 1.39.2.3
retrieving revision 1.39.2.4
diff -u -d -r1.39.2.3 -r1.39.2.4
--- res_musiconhold.c	8 Jan 2005 21:54:24 -0000	1.39.2.3
+++ res_musiconhold.c	4 Aug 2005 23:45:54 -0000	1.39.2.4
@@ -108,6 +108,21 @@
 #define MPG_123 "/usr/bin/mpg123"
 #define MAX_MP3S 256
 
+
+static void ast_moh_free_class(struct mohclass **class) 
+{
+	struct mohdata *members, *mtmp;
+	
+	members = (*class)->members;
+	while(members) {
+		mtmp = members;
+		members = members->next;
+		free(mtmp);
+	}
+	free(*class);
+	*class = NULL;
+}
+
 static int spawn_mp3(struct mohclass *class)
 {
 	int fds[2];
@@ -574,12 +589,12 @@
 			ast_log(LOG_WARNING, "Unable to create moh...\n");
 			if (moh->pseudofd > -1)
 				close(moh->pseudofd);
-			free(moh);
+			ast_moh_free_class(&moh);
 			return -1;
 		}
 	} else {
 		ast_log(LOG_WARNING, "Don't know how to do a mode '%s' music on hold\n", mode);
-		free(moh);
+		ast_moh_free_class(&moh);
 		return -1;
 	}
 	ast_mutex_lock(&moh_lock);




More information about the svn-commits mailing list