summaryrefslogtreecommitdiffstats
path: root/rpc
diff options
context:
space:
mode:
authorAmar Tumballi <amar@gluster.com>2010-08-11 05:58:31 +0000
committerAnand V. Avati <avati@dev.gluster.com>2010-08-12 00:14:27 -0700
commitd8bb87b4c7dd40adf4fe0ba0a0946483599e0acc (patch)
treefa12f319b8eececf9852a6f9e9e87206c016b214 /rpc
parentfe38de53620d2c8c9dd1050a377f05a315f125d8 (diff)
rpc fixes
* set THIS properly so memory accounting works fine. * also check for few pointers before dereferencing them. Signed-off-by: Amar Tumballi <amar@gluster.com> Signed-off-by: Anand V. Avati <avati@dev.gluster.com> BUG: 1317 () URL: http://bugs.gluster.com/cgi-bin/bugzilla3/show_bug.cgi?id=1317
Diffstat (limited to 'rpc')
-rw-r--r--rpc/rpc-lib/src/rpc-transport.c3
-rw-r--r--rpc/rpc-lib/src/rpc-transport.h1
-rw-r--r--rpc/rpc-transport/socket/src/socket.c26
3 files changed, 22 insertions, 8 deletions
diff --git a/rpc/rpc-lib/src/rpc-transport.c b/rpc/rpc-lib/src/rpc-transport.c
index 42274ed8d..c21d5ecfc 100644
--- a/rpc/rpc-lib/src/rpc-transport.c
+++ b/rpc/rpc-lib/src/rpc-transport.c
@@ -956,6 +956,7 @@ rpc_transport_load (glusterfs_ctx_t *ctx, dict_t *options, char *trans_name)
trans->options = options;
pthread_mutex_init (&trans->lock, NULL);
+ trans->xl = THIS;
return_trans = trans;
return return_trans;
@@ -1054,8 +1055,6 @@ rpc_transport_destroy (rpc_transport_t *this)
GF_VALIDATE_OR_GOTO("rpc_transport", this, fail);
- rpc_transport_disconnect (this);
-
if (this->fini)
this->fini (this);
pthread_mutex_destroy (&this->lock);
diff --git a/rpc/rpc-lib/src/rpc-transport.h b/rpc/rpc-lib/src/rpc-transport.h
index f6576fc13..14ec8bc57 100644
--- a/rpc/rpc-lib/src/rpc-transport.h
+++ b/rpc/rpc-lib/src/rpc-transport.h
@@ -170,6 +170,7 @@ struct rpc_transport {
struct rpc_transport_ops *ops;
void *private;
void *xl_private;
+ void *xl; /* Used for THIS */
void *mydata;
pthread_mutex_t lock;
int32_t refcount;
diff --git a/rpc/rpc-transport/socket/src/socket.c b/rpc/rpc-transport/socket/src/socket.c
index b017462a5..e544332c0 100644
--- a/rpc/rpc-transport/socket/src/socket.c
+++ b/rpc/rpc-transport/socket/src/socket.c
@@ -1497,8 +1497,12 @@ socket_event_handler (int fd, int idx, void *data,
int ret = 0;
this = data;
+ THIS = this->xl;
priv = this->private;
+ if (!priv)
+ return 0;
+
pthread_mutex_lock (&priv->lock);
{
priv->idx = idx;
@@ -1542,9 +1546,13 @@ socket_server_event_handler (int fd, int idx, void *data,
glusterfs_ctx_t *ctx = NULL;
this = data;
+ THIS = this->xl;
priv = this->private;
ctx = this->ctx;
+ if (!priv)
+ return 0;
+
pthread_mutex_lock (&priv->lock);
{
priv->idx = idx;
@@ -1584,7 +1592,6 @@ socket_server_event_handler (int fd, int idx, void *data,
if (!new_trans)
goto unlock;
- new_trans->fini = this->fini;
new_trans->name = gf_strdup (this->name);
memcpy (&new_trans->peerinfo.sockaddr, &new_sockaddr,
@@ -1611,6 +1618,7 @@ socket_server_event_handler (int fd, int idx, void *data,
new_trans->init = this->init;
new_trans->fini = this->fini;
new_trans->ctx = ctx;
+ new_trans->xl = this->xl;
new_trans->mydata = this->mydata;
new_trans->notify = this->notify;
new_priv = new_trans->private;
@@ -2323,13 +2331,19 @@ fini (rpc_transport_t *this)
{
socket_private_t *priv = this->private;
- gf_log (this->name, GF_LOG_TRACE,
- "transport %p destroyed", this);
+ this->private = NULL;
+ if (priv) {
+ gf_log (this->name, GF_LOG_TRACE,
+ "transport %p destroyed", this);
- pthread_mutex_destroy (&priv->lock);
+ pthread_mutex_destroy (&priv->lock);
+ GF_FREE (priv);
+ }
- GF_FREE (this->name);
- GF_FREE (priv);
+ if (this->name) {
+ GF_FREE (this->name);
+ this->name = NULL;
+ }
}