Revision
15431
Author
mikej
Date
2009-11-11 10:59:25 -0600 (Wed, 11 Nov 2009)

Log Message

Memory leak at mod_local_stream (MODFORM-36)

Modified Paths

Diff

Modified: freeswitch/trunk/src/mod/formats/mod_local_stream/mod_local_stream.c (15430 => 15431)


--- freeswitch/trunk/src/mod/formats/mod_local_stream/mod_local_stream.c	2009-11-11 16:39:39 UTC (rev 15430)
+++ freeswitch/trunk/src/mod/formats/mod_local_stream/mod_local_stream.c	2009-11-11 16:59:25 UTC (rev 15431)
@@ -119,6 +119,7 @@
 	switch_byte_t *dist_buf;
 	switch_size_t used;
 	int skip = 0;
+	switch_memory_pool_t *temp_pool = NULL;
 
 	switch_mutex_lock(globals.mutex);
 	THREADS++;
@@ -146,8 +147,17 @@
 
 	while (RUNNING && !source->stopped) {
 		const char *fname;
+
+		if (temp_pool) {
+			switch_core_destroy_memory_pool(&temp_pool);
+		}
+
+		if (switch_core_new_memory_pool(&temp_pool) != SWITCH_STATUS_SUCCESS) {
+			switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "Error creating pool");
+			goto done;
+		}
 		
-		if (switch_dir_open(&source->dir_handle, source->location, source->pool) != SWITCH_STATUS_SUCCESS) {
+		if (switch_dir_open(&source->dir_handle, source->location, temp_pool) != SWITCH_STATUS_SUCCESS) {
 			switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CONSOLE, "Can't open directory: %s\n", source->location);
 			goto done;
 		}
@@ -202,7 +212,7 @@
 				continue;
 			}
 			
-			if (switch_core_timer_init(&timer, source->timer_name, source->interval, source->samples, source->pool) != SWITCH_STATUS_SUCCESS) {
+			if (switch_core_timer_init(&timer, source->timer_name, source->interval, source->samples, temp_pool) != SWITCH_STATUS_SUCCESS) {
 				switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CONSOLE, "Can't start timer.\n");
 				switch_dir_close(source->dir_handle);
 				source->dir_handle = NULL;
@@ -336,6 +346,10 @@
 		close(fd);
 	}
 
+	if (temp_pool) {
+		switch_core_destroy_memory_pool(&temp_pool);
+	}
+
 	switch_core_destroy_memory_pool(&source->pool);
 
 	switch_mutex_lock(globals.mutex);