summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPranith Kumar K <pkarampu@redhat.com>2014-08-26 12:59:47 +0530
committerKaleb KEITHLEY <kkeithle@redhat.com>2014-08-27 06:46:38 -0700
commitf0ddba7e0913db505f1295e9b3b7d35ead9c4407 (patch)
treead28e42375e834b0c5cb97a3e68000e187e4dd73
parent1679b72c5b023884fb4bc6a2a85b06016fb3cab8 (diff)
cluster/afr: Fix memory leak of file-path in self-heal-daemon
Backport of http://review.gluster.org/4790 Note: Only the part which fixes the memory leak is backported shd event has path which needs to be freed as part of circular buffer cleanup. This patch introduces the functionality so that self-heal-daemon can use it. Change-Id: I3f3823d5587eda2fcb278f0fdb89123a31c9d786 BUG: 1119894 Signed-off-by: Pranith Kumar K <pkarampu@redhat.com> Reviewed-on: http://review.gluster.org/8541 Tested-by: Gluster Build System <jenkins@build.gluster.com> Reviewed-by: Ravishankar N <ravishankar@redhat.com> Reviewed-by: Kaleb KEITHLEY <kkeithle@redhat.com>
-rw-r--r--libglusterfs/src/circ-buff.c30
-rw-r--r--libglusterfs/src/circ-buff.h5
-rw-r--r--libglusterfs/src/event-history.c6
-rw-r--r--libglusterfs/src/event-history.h3
-rw-r--r--xlators/cluster/afr/src/afr-self-heald.c12
-rw-r--r--xlators/cluster/afr/src/afr.c9
-rw-r--r--xlators/cluster/afr/src/afr.h2
-rw-r--r--xlators/debug/trace/src/trace.c2
-rw-r--r--xlators/mount/fuse/src/fuse-bridge.c2
9 files changed, 56 insertions, 15 deletions
diff --git a/libglusterfs/src/circ-buff.c b/libglusterfs/src/circ-buff.c
index 65bbd5d..28b42d5 100644
--- a/libglusterfs/src/circ-buff.c
+++ b/libglusterfs/src/circ-buff.c
@@ -10,6 +10,17 @@
#include "circ-buff.h"
+void
+cb_destroy_data (circular_buffer_t *cb,
+ void (*destroy_buffer_data) (void *data))
+{
+ if (destroy_buffer_data)
+ destroy_buffer_data (cb->data);
+ GF_FREE (cb->data);
+ return;
+}
+
+
/* hold lock while calling this function */
int
__cb_add_entry_buffer (buffer_t *buffer, void *item)
@@ -29,7 +40,8 @@ __cb_add_entry_buffer (buffer_t *buffer, void *item)
if (buffer->cb[buffer->w_index]) {
ptr = buffer->cb[buffer->w_index];
if (ptr->data) {
- GF_FREE (ptr->data);
+ cb_destroy_data (ptr,
+ buffer->destroy_buffer_data);
ptr->data = NULL;
GF_FREE (ptr);
}
@@ -118,7 +130,8 @@ cb_buffer_dump (buffer_t *buffer, void *data,
}
buffer_t *
-cb_buffer_new (size_t buffer_size, gf_boolean_t use_once)
+cb_buffer_new (size_t buffer_size, gf_boolean_t use_once,
+ void (*destroy_buffer_data) (void *data))
{
buffer_t *buffer = NULL;
@@ -144,6 +157,7 @@ cb_buffer_new (size_t buffer_size, gf_boolean_t use_once)
buffer->size_buffer = buffer_size;
buffer->use_once = use_once;
buffer->used_len = 0;
+ buffer->destroy_buffer_data = destroy_buffer_data;
pthread_mutex_init (&buffer->lock, NULL);
out:
@@ -153,12 +167,18 @@ out:
void
cb_buffer_destroy (buffer_t *buffer)
{
- int i = 0;
-
+ int i = 0;
+ circular_buffer_t *ptr = NULL;
if (buffer) {
if (buffer->cb) {
for (i = 0; i < buffer->used_len ; i++) {
- GF_FREE (buffer->cb[i]);
+ ptr = buffer->cb[i];
+ if (ptr->data) {
+ cb_destroy_data (ptr,
+ buffer->destroy_buffer_data);
+ ptr->data = NULL;
+ GF_FREE (ptr);
+ }
}
GF_FREE (buffer->cb);
}
diff --git a/libglusterfs/src/circ-buff.h b/libglusterfs/src/circ-buff.h
index 5b5acc3..e3459f5 100644
--- a/libglusterfs/src/circ-buff.h
+++ b/libglusterfs/src/circ-buff.h
@@ -38,7 +38,7 @@ struct _buffer {
/* indicates the amount of circular buffer used. */
circular_buffer_t **cb;
-
+ void (*destroy_buffer_data) (void *data);
pthread_mutex_t lock;
};
@@ -51,7 +51,8 @@ void
cb_buffer_show (buffer_t *buffer);
buffer_t *
-cb_buffer_new (size_t buffer_size,gf_boolean_t use_buffer_once);
+cb_buffer_new (size_t buffer_size,gf_boolean_t use_buffer_once,
+ void (*destroy_data) (void *data));
void
cb_buffer_destroy (buffer_t *buffer);
diff --git a/libglusterfs/src/event-history.c b/libglusterfs/src/event-history.c
index fe511ca..82baa52 100644
--- a/libglusterfs/src/event-history.c
+++ b/libglusterfs/src/event-history.c
@@ -11,7 +11,8 @@
#include "event-history.h"
eh_t *
-eh_new (size_t buffer_size, gf_boolean_t use_buffer_once)
+eh_new (size_t buffer_size, gf_boolean_t use_buffer_once,
+ void (*destroy_buffer_data) (void *data))
{
eh_t *history = NULL;
buffer_t *buffer = NULL;
@@ -22,7 +23,8 @@ eh_new (size_t buffer_size, gf_boolean_t use_buffer_once)
goto out;
}
- buffer = cb_buffer_new (buffer_size, use_buffer_once);
+ buffer = cb_buffer_new (buffer_size, use_buffer_once,
+ destroy_buffer_data);
if (!buffer) {
gf_log ("", GF_LOG_ERROR, "allocating circular buffer failed");
GF_FREE (history);
diff --git a/libglusterfs/src/event-history.h b/libglusterfs/src/event-history.h
index b1750bb..b64f63b 100644
--- a/libglusterfs/src/event-history.h
+++ b/libglusterfs/src/event-history.h
@@ -32,7 +32,8 @@ eh_dump (eh_t *event , void *data,
int (fn) (circular_buffer_t *buffer, void *data));
eh_t *
-eh_new (size_t buffer_size, gf_boolean_t use_buffer_once);
+eh_new (size_t buffer_size, gf_boolean_t use_buffer_once,
+ void (*destroy_data) (void *data));
int
eh_save_history (eh_t *history, void *string);
diff --git a/xlators/cluster/afr/src/afr-self-heald.c b/xlators/cluster/afr/src/afr-self-heald.c
index 37bc224..c5d7acb 100644
--- a/xlators/cluster/afr/src/afr-self-heald.c
+++ b/xlators/cluster/afr/src/afr-self-heald.c
@@ -65,6 +65,18 @@ afr_find_child_position (xlator_t *this, int child, afr_child_pos_t *pos);
int
afr_syncop_find_child_position (void *data);
+void
+_destroy_shd_event_data (void *data)
+{
+ shd_event_t *event = NULL;
+ if (!data)
+ goto out;
+ event = (shd_event_t*)data;
+ GF_FREE (event->path);
+out:
+ return;
+}
+
static int
_loc_assign_gfid_path (loc_t *loc)
{
diff --git a/xlators/cluster/afr/src/afr.c b/xlators/cluster/afr/src/afr.c
index d49a39d..70f74a2 100644
--- a/xlators/cluster/afr/src/afr.c
+++ b/xlators/cluster/afr/src/afr.c
@@ -430,15 +430,18 @@ init (xlator_t *this)
if (!priv->shd.timer)
goto out;
- priv->shd.healed = eh_new (AFR_EH_HEALED_LIMIT, _gf_false);
+ priv->shd.healed = eh_new (AFR_EH_HEALED_LIMIT, _gf_false,
+ _destroy_shd_event_data);
if (!priv->shd.healed)
goto out;
- priv->shd.heal_failed = eh_new (AFR_EH_HEAL_FAIL_LIMIT, _gf_false);
+ priv->shd.heal_failed = eh_new (AFR_EH_HEAL_FAIL_LIMIT, _gf_false,
+ _destroy_shd_event_data);
if (!priv->shd.heal_failed)
goto out;
- priv->shd.split_brain = eh_new (AFR_EH_SPLIT_BRAIN_LIMIT, _gf_false);
+ priv->shd.split_brain = eh_new (AFR_EH_SPLIT_BRAIN_LIMIT, _gf_false,
+ _destroy_shd_event_data);
if (!priv->shd.split_brain)
goto out;
diff --git a/xlators/cluster/afr/src/afr.h b/xlators/cluster/afr/src/afr.h
index 84e8907..0a2b001 100644
--- a/xlators/cluster/afr/src/afr.h
+++ b/xlators/cluster/afr/src/afr.h
@@ -1054,6 +1054,8 @@ afr_is_errno_unset (int *child_errno, int child);
gf_boolean_t
afr_is_fd_fixable (fd_t *fd);
+void _destroy_shd_event_data (void *data);
+
void
afr_prepare_new_entry_pending_matrix (int32_t **pending,
gf_boolean_t (*is_pending) (int *, int),
diff --git a/xlators/debug/trace/src/trace.c b/xlators/debug/trace/src/trace.c
index 1215dd6..bdc9567 100644
--- a/xlators/debug/trace/src/trace.c
+++ b/xlators/debug/trace/src/trace.c
@@ -3134,7 +3134,7 @@ init (xlator_t *this)
gf_log (this->name, GF_LOG_DEBUG, "logging to history %s",
(conf->log_history == _gf_true)?"enabled":"disabled");
- history = eh_new (history_size, _gf_false);
+ history = eh_new (history_size, _gf_false, NULL);
if (!history) {
gf_log (this->name, GF_LOG_ERROR, "event history cannot be "
"initialized");
diff --git a/xlators/mount/fuse/src/fuse-bridge.c b/xlators/mount/fuse/src/fuse-bridge.c
index da5937b..8cde71c 100644
--- a/xlators/mount/fuse/src/fuse-bridge.c
+++ b/xlators/mount/fuse/src/fuse-bridge.c
@@ -5193,7 +5193,7 @@ init (xlator_t *this_xl)
if (priv->fd == -1)
goto cleanup_exit;
- event = eh_new (FUSE_EVENT_HISTORY_SIZE, _gf_false);
+ event = eh_new (FUSE_EVENT_HISTORY_SIZE, _gf_false, NULL);
if (!event) {
gf_log (this_xl->name, GF_LOG_ERROR,
"could not create a new event history");