diff options
author | Junaid <junaid@gluster.com> | 2011-03-25 01:49:07 +0000 |
---|---|---|
committer | Vijay Bellur <vijay@dev.gluster.com> | 2011-03-26 06:45:46 -0700 |
commit | a9a6d95ecb86f45b197bc36d8e6a504d65367c3a (patch) | |
tree | 18aa74dac7533c080bd6edb5ce394ff7fbbf340e /xlators/cluster/dht/src | |
parent | 0952bbb30564e8a2359039841290f9956c96e1b9 (diff) |
cluster/dht: Fix double freeing in quota aggregate.
Signed-off-by: Junaid <junaid@gluster.com>
Signed-off-by: Vijay Bellur <vijay@dev.gluster.com>
BUG: 2473 (Support for volume and directory level quota)
URL: http://bugs.gluster.com/cgi-bin/bugzilla3/show_bug.cgi?id=2473
Diffstat (limited to 'xlators/cluster/dht/src')
-rw-r--r-- | xlators/cluster/dht/src/dht-common.c | 33 |
1 files changed, 23 insertions, 10 deletions
diff --git a/xlators/cluster/dht/src/dht-common.c b/xlators/cluster/dht/src/dht-common.c index 25aa3c444db..57cf57578ac 100644 --- a/xlators/cluster/dht/src/dht-common.c +++ b/xlators/cluster/dht/src/dht-common.c @@ -40,24 +40,37 @@ void dht_aggregate (dict_t *this, char *key, data_t *value, void *data) { dict_t *dst = NULL; - int64_t *ptr = 0, size = 0; + int64_t *ptr = 0, *size = NULL; int32_t ret = -1; dst = data; - if (strncmp (key, GF_XATTR_QUOTA_SIZE_KEY, - strlen (GF_XATTR_QUOTA_SIZE_KEY)) == 0) { - ret = dict_get_bin (dst, key, (void **)&ptr); - if (ret == 0) { - size = ntoh64 (*ptr); + if (strcmp (key, GF_XATTR_QUOTA_SIZE_KEY) == 0) { + ret = dict_get_bin (dst, key, (void **)&size); + if (ret < 0) { + size = GF_CALLOC (1, sizeof (int64_t), + gf_common_mt_char); + if (size == NULL) { + gf_log ("dht", GF_LOG_WARNING, + "memory allocation failed"); + return; + } + ret = dict_set_bin (dst, key, size, sizeof (int64_t)); + if (ret < 0) { + gf_log ("dht", GF_LOG_WARNING, + "dht aggregate dict set failed"); + GF_FREE (size); + return; + } } ptr = data_to_bin (value); + if (ptr == NULL) { + gf_log ("dht", GF_LOG_WARNING, "data to bin failed"); + return; + } - size += ntoh64 (*ptr); - - *ptr = hton64 (*ptr); - ret = dict_set_bin (dst, key, ptr, sizeof (int64_t)); + *size = hton64 (ntoh64 (*size) + ntoh64 (*ptr)); } return; |