summaryrefslogtreecommitdiffstats
path: root/rpc
diff options
context:
space:
mode:
authorRaghavendra G <raghavendra@gluster.com>2010-09-04 04:07:58 +0000
committerVijay Bellur <vijay@dev.gluster.com>2010-09-04 04:17:10 -0700
commit4f708eb8bbc80e5107fc3679b9f7ccac51883782 (patch)
tree3edf25ba4a585da9db743a4fec26733363a50009 /rpc
parent1972bd268f1a989d063701de2afee73c15059e01 (diff)
rpc-transport/socket: fix memory leaks.
- In the course of reading a single rpc-msg, socket_proto_state_machine may be executed multiple times (since sockets are non-blocking), hence wherever memory is allocated or referenced, checks should be added whether the memory is already allocated or referenced. Signed-off-by: Raghavendra G <raghavendra@gluster.com> Signed-off-by: Vijay Bellur <vijay@dev.gluster.com> BUG: 1438 (memory leaks) URL: http://bugs.gluster.com/cgi-bin/bugzilla3/show_bug.cgi?id=1438
Diffstat (limited to 'rpc')
-rw-r--r--rpc/rpc-transport/socket/src/socket.c46
1 files changed, 28 insertions, 18 deletions
diff --git a/rpc/rpc-transport/socket/src/socket.c b/rpc/rpc-transport/socket/src/socket.c
index f7d4d8e40..d3167fe0b 100644
--- a/rpc/rpc-transport/socket/src/socket.c
+++ b/rpc/rpc-transport/socket/src/socket.c
@@ -1213,6 +1213,7 @@ __socket_read_reply (rpc_transport_t *this)
char *buf = NULL;
int32_t ret = -1;
rpc_request_info_t *request_info = NULL;
+ char map_xid = 0;
if (!this || !this->private)
goto out;
@@ -1221,33 +1222,42 @@ __socket_read_reply (rpc_transport_t *this)
buf = rpc_xid_addr (iobuf_ptr (priv->incoming.iobuf));
- request_info = GF_CALLOC (1, sizeof (*request_info), gf_common_mt_rpc_trans_reqinfo_t);
- if (request_info == NULL) {
- gf_log (this->name, GF_LOG_ERROR, "out of memory");
- goto out;
+ if (priv->incoming.request_info == NULL) {
+ priv->incoming.request_info = GF_CALLOC (1,
+ sizeof (*request_info),
+ gf_common_mt_rpc_trans_reqinfo_t);
+ if (priv->incoming.request_info == NULL) {
+ gf_log (this->name, GF_LOG_ERROR, "out of memory");
+ goto out;
+ }
+
+ map_xid = 1;
}
- priv->incoming.request_info = request_info;
+ request_info = priv->incoming.request_info;
- request_info->xid = ntoh32 (*((uint32_t *) buf));
+ if (map_xid) {
+ request_info->xid = ntoh32 (*((uint32_t *) buf));
- /* release priv->lock, so as to avoid deadlock b/w conn->lock and
- * priv->lock, since we are doing an upcall here.
- */
- pthread_mutex_unlock (&priv->lock);
- {
- ret = rpc_transport_notify (this, RPC_TRANSPORT_MAP_XID_REQUEST,
- priv->incoming.request_info);
- }
- pthread_mutex_lock (&priv->lock);
+ /* release priv->lock, so as to avoid deadlock b/w conn->lock
+ * and priv->lock, since we are doing an upcall here.
+ */
+ pthread_mutex_unlock (&priv->lock);
+ {
+ ret = rpc_transport_notify (this,
+ RPC_TRANSPORT_MAP_XID_REQUEST,
+ priv->incoming.request_info);
+ }
+ pthread_mutex_lock (&priv->lock);
- if (ret == -1) {
- goto out;
+ if (ret == -1) {
+ goto out;
+ }
}
if ((request_info->prognum == GLUSTER3_1_FOP_PROGRAM)
&& (request_info->procnum == GF_FOP_READ)) {
- if (request_info->rsp.rsp_payload_count != 0) {
+ if (map_xid && request_info->rsp.rsp_payload_count != 0) {
priv->incoming.iobref
= iobref_ref (request_info->rsp.rsp_iobref);
priv->incoming.payload_vector