From b0003a7e789e0618656dd4214195578f53d1e84e Mon Sep 17 00:00:00 2001 From: Pranith Kumar K Date: Tue, 14 Sep 2010 00:54:22 +0000 Subject: mgmt/glusterd: free xdr allocations Signed-off-by: Pranith Kumar K Signed-off-by: Vijay Bellur BUG: 1186 () URL: http://bugs.gluster.com/cgi-bin/bugzilla3/show_bug.cgi?id=1186 --- libglusterfs/src/dict.c | 49 +++++++++++++++++++++++++++++++++++++++++++++++-- libglusterfs/src/dict.h | 3 +++ 2 files changed, 50 insertions(+), 2 deletions(-) (limited to 'libglusterfs') diff --git a/libglusterfs/src/dict.c b/libglusterfs/src/dict.c index 7a47a57b..b1c1a5d9 100644 --- a/libglusterfs/src/dict.c +++ b/libglusterfs/src/dict.c @@ -140,8 +140,12 @@ data_destroy (data_t *data) LOCK_DESTROY (&data->lock); if (!data->is_static) { - if (data->data) - GF_FREE (data->data); + if (data->data) { + if (data->is_stdalloc) + free (data->data); + else + GF_FREE (data->data); + } if (data->vec) GF_FREE (data->vec); } @@ -413,6 +417,8 @@ dict_destroy (dict_t *this) if (this->extra_free) GF_FREE (this->extra_free); + if (this->extra_stdfree) + free (this->extra_stdfree); if (!this->is_static) GF_FREE (this); @@ -1031,6 +1037,24 @@ data_from_dynstr (char *value) return data; } +data_t * +data_from_dynmstr (char *value) +{ + if (!value) { + gf_log ("dict", GF_LOG_CRITICAL, + "@value=%p", value); + return NULL; + } + + data_t *data = get_new_data (); + + data->len = strlen (value) + 1; + data->data = value; + data->is_stdalloc = 1; + + return data; +} + data_t * data_from_dynptr (void *value, int32_t len) { @@ -2041,6 +2065,27 @@ err: return ret; } +/* + for malloced strings we should do a free instead of GF_FREE +*/ +int +dict_set_dynmstr (dict_t *this, char *key, char *str) +{ + data_t * data = NULL; + int ret = 0; + + data = data_from_dynmstr (str); + if (!data) { + ret = -EINVAL; + goto err; + } + + ret = dict_set (this, key, data); + +err: + return ret; +} + int dict_get_bin (dict_t *this, char *key, void **bin) diff --git a/libglusterfs/src/dict.h b/libglusterfs/src/dict.h index 508b139a..41b6b678 100644 --- a/libglusterfs/src/dict.h +++ b/libglusterfs/src/dict.h @@ -38,6 +38,7 @@ typedef struct _data_pair data_pair_t; struct _data { unsigned char is_static:1; unsigned char is_const:1; + unsigned char is_stdalloc:1; int32_t len; struct iovec *vec; char *data; @@ -61,6 +62,7 @@ struct _dict { data_pair_t **members; data_pair_t *members_list; char *extra_free; + char *extra_stdfree; gf_lock_t lock; }; @@ -179,6 +181,7 @@ GF_MUST_CHECK int dict_set_bin (dict_t *this, char *key, void *ptr, size_t size) GF_MUST_CHECK int dict_set_static_bin (dict_t *this, char *key, void *ptr, size_t size); GF_MUST_CHECK int dict_set_str (dict_t *this, char *key, char *str); +GF_MUST_CHECK int dict_set_dynmstr (dict_t *this, char *key, char *str); GF_MUST_CHECK int dict_set_dynstr (dict_t *this, char *key, char *str); GF_MUST_CHECK int dict_get_str (dict_t *this, char *key, char **str); -- cgit