From fe59c3485406cda02950e20f57d0ecc0cf964546 Mon Sep 17 00:00:00 2001 From: Pranith Kumar K Date: Mon, 23 Jun 2014 12:09:30 +0530 Subject: debug/io-stats: Free conf on init failures Change-Id: I1d227f7b2b8f8ad8d44df8711654ee885e79cf38 BUG: 1111557 Signed-off-by: Pranith Kumar K Reviewed-on: http://review.gluster.org/8148 Tested-by: Gluster Build System Reviewed-by: Krutika Dhananjay Reviewed-by: Vijay Bellur --- xlators/debug/io-stats/src/io-stats.c | 38 +++++++++++++++++++++-------------- 1 file changed, 23 insertions(+), 15 deletions(-) (limited to 'xlators/debug/io-stats/src') diff --git a/xlators/debug/io-stats/src/io-stats.c b/xlators/debug/io-stats/src/io-stats.c index 6a2aa586ab1..8cc4bf13bf1 100644 --- a/xlators/debug/io-stats/src/io-stats.c +++ b/xlators/debug/io-stats/src/io-stats.c @@ -381,6 +381,7 @@ ios_stat_unref (struct ios_stat *iosstat) UNLOCK (&iosstat->lock); if (cleanup) { + LOCK_DESTROY (&iosstat->lock); GF_FREE (iosstat); iosstat = NULL; } @@ -2747,6 +2748,17 @@ mem_acct_init (xlator_t *this) return ret; } +void +ios_conf_destroy (struct ios_conf *conf) +{ + if (!conf) + return; + + ios_destroy_top_stats (conf); + LOCK_DESTROY (&conf->lock); + GF_FREE(conf); +} + int init (xlator_t *this) { @@ -2782,12 +2794,13 @@ init (xlator_t *this) conf = GF_CALLOC (1, sizeof(*conf), gf_io_stats_mt_ios_conf); - if (!conf) { - gf_log (this->name, GF_LOG_ERROR, - "Out of memory."); - return -1; - } + if (!conf) + goto out; + /* + * Init it just after calloc, so that we are sure the lock is inited + * in case of error paths. + */ LOCK_INIT (&conf->lock); gettimeofday (&conf->cumulative.started_at, NULL); @@ -2795,7 +2808,7 @@ init (xlator_t *this) ret = ios_init_top_stats (conf); if (ret) - return -1; + goto out; GF_OPTION_INIT ("dump-fd-stats", conf->dump_fd_stats, bool, out); @@ -2838,13 +2851,14 @@ init (xlator_t *this) this->private = conf; ret = 0; out: - if (!this->private) + if (!this->private) { + ios_conf_destroy (conf); ret = -1; + } return ret; } - void fini (xlator_t *this) { @@ -2854,15 +2868,9 @@ fini (xlator_t *this) return; conf = this->private; - - if (!conf) - return; this->private = NULL; - ios_destroy_top_stats (conf); - - GF_FREE(conf); - + ios_conf_destroy (conf); gf_log (this->name, GF_LOG_INFO, "io-stats translator unloaded"); return; -- cgit