summaryrefslogtreecommitdiffstats
path: root/rpc
diff options
context:
space:
mode:
authorNikhil Ladha <nladha@redhat.com>2020-11-12 14:04:27 +0530
committerGitHub <noreply@github.com>2020-11-12 09:34:27 +0100
commitb8ad18a260bf1fb34af92bd948df9142e0a08f51 (patch)
tree3d62180f10dd676e9a36674c570a1b3480f5b1c3 /rpc
parent4026fe9a956238d8e4785cf39c3b7290eae90f03 (diff)
downloadglusterfs-b8ad18a260bf1fb34af92bd948df9142e0a08f51.tar.gz
glusterfs-b8ad18a260bf1fb34af92bd948df9142e0a08f51.tar.xz
glusterfs-b8ad18a260bf1fb34af92bd948df9142e0a08f51.zip
glusterd: resource leaks (#1748)
Issue: iobref was not freed before exiting the function if all the checks were OK, which caused the resource leak. Fix: Modified the code a bit to avoid use of an extra reference to the label, and to free the iobref and iobuf if not NULL, and then exit the function. CID: 1430118 Updates: #1060
Diffstat (limited to 'rpc')
-rw-r--r--rpc/rpc-lib/src/rpc-clnt.c14
1 files changed, 11 insertions, 3 deletions
diff --git a/rpc/rpc-lib/src/rpc-clnt.c b/rpc/rpc-lib/src/rpc-clnt.c
index 517037c4a5..f0b95e26cb 100644
--- a/rpc/rpc-lib/src/rpc-clnt.c
+++ b/rpc/rpc-lib/src/rpc-clnt.c
@@ -1611,6 +1611,7 @@ rpc_clnt_submit(struct rpc_clnt *rpc, rpc_clnt_prog_t *prog, int procnum,
0,
};
struct rpc_req *rpcreq = NULL;
+ struct rpc_req rpcreq_static;
rpc_transport_req_t req;
int ret = -1;
int proglen = 0;
@@ -1636,6 +1637,7 @@ rpc_clnt_submit(struct rpc_clnt *rpc, rpc_clnt_prog_t *prog, int procnum,
if (!iobref) {
iobref = iobref_new();
if (!iobref) {
+ ret = -1;
goto out;
}
@@ -1750,9 +1752,15 @@ out:
}
if (frame && (ret == -1)) {
- if (rpcreq) {
- rpcreq->rpc_status = -1;
- cbkfn(rpcreq, NULL, 0, frame);
+ if (!rpcreq) {
+ memset(&rpcreq_static, 0,
+ sizeof(rpcreq_static)); /* To handle frame destroy in case
+ rpcreq was not defined */
+ rpcreq = &rpcreq_static;
+ }
+ rpcreq->rpc_status = -1;
+ cbkfn(rpcreq, NULL, 0, frame);
+ if (rpcreq != &rpcreq_static) {
mem_put(rpcreq);
}
}