From 804c4fb84e132187c4b1d68e50a5577d0ce8afa2 Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Tue, 16 Sep 2008 15:20:40 +0000 Subject: [PATCH] refactor git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@9572 d0543943-73ff-0310-b7d9-9358b9ac24b2 --- src/mod/loggers/mod_logfile/mod_logfile.c | 27 +++++++++-------------- 1 file changed, 11 insertions(+), 16 deletions(-) diff --git a/src/mod/loggers/mod_logfile/mod_logfile.c b/src/mod/loggers/mod_logfile/mod_logfile.c index e51817ce3a..57568e9900 100644 --- a/src/mod/loggers/mod_logfile/mod_logfile.c +++ b/src/mod/loggers/mod_logfile/mod_logfile.c @@ -113,10 +113,10 @@ static switch_status_t mod_logfile_openlogfile(logfile_profile_t *profile, switc static switch_status_t mod_logfile_rotate(logfile_profile_t *profile) { unsigned int i = 0; - char *p = NULL; + char *filename = NULL; switch_status_t stat = 0; int64_t offset = 0; - switch_memory_pool_t *pool; + switch_memory_pool_t *pool = NULL; switch_time_exp_t tm; char date[80] = ""; switch_size_t retsize; @@ -136,36 +136,31 @@ static switch_status_t mod_logfile_rotate(logfile_profile_t *profile) goto end; } - - p = malloc(strlen(profile->logfile) + WARM_FUZZY_OFFSET); - switch_assert(p); - - memset(p, '\0', strlen(profile->logfile) + WARM_FUZZY_OFFSET); - switch_core_new_memory_pool(&pool); + filename = switch_core_alloc(pool, strlen(profile->logfile) + WARM_FUZZY_OFFSET); for (i = 1; i < MAX_ROT; i++) { - sprintf((char *) p, "%s.%s.%i", profile->logfile, date, i); - if (switch_file_exists(p, pool) == SWITCH_STATUS_SUCCESS) { + sprintf((char *) filename, "%s.%s.%i", profile->logfile, date, i); + if (switch_file_exists(filename, pool) == SWITCH_STATUS_SUCCESS) { continue; } switch_file_close(profile->log_afd); - switch_file_rename(profile->logfile, p, pool); + switch_file_rename(profile->logfile, filename, pool); if ((status = mod_logfile_openlogfile(profile, SWITCH_FALSE)) != SWITCH_STATUS_SUCCESS) { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "Error Rotating Log!\n"); goto end; } break; } - - free(p); - - switch_core_destroy_memory_pool(&pool); - + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_NOTICE, "New log started.\n"); end: + + if (pool) { + switch_core_destroy_memory_pool(&pool); + } switch_mutex_unlock(globals.mutex);