diff options
author | Kinglong Mee <kinglongmee@gmail.com> | 2019-01-18 10:38:14 +0800 |
---|---|---|
committer | Amar Tumballi <amarts@redhat.com> | 2019-01-21 03:11:20 +0000 |
commit | c5bb929b367121f2610f74630882254da7fd882a (patch) | |
tree | d6e9a697eb50eaee576ad48df1f9ddf719265938 | |
parent | 0687b0beb5cc58d5aac9e203f0feebcd7e9eea03 (diff) |
quotad: fix wrong memory free
1. cli_req.dict.dict_val,
It must be freed no metter operation error or success.
Fix it as lookup "alloca" memory before decode.
2. args.xdata.xdata_val,
It is allocated by "alloca", free is unneeded.
3. qd_nameless_lookup,
It olny needs gfid, a gfs3_lookup_req argument is unneeded.
Change-Id: I746dddf7f3d1465b1885af2644afe0bcf0a5665b
fixes: bz#1656682
Signed-off-by: Kinglong Mee <mijinlong@open-fs.com>
-rw-r--r-- | xlators/features/quota/src/quotad-aggregator.c | 20 | ||||
-rw-r--r-- | xlators/features/quota/src/quotad-aggregator.h | 2 | ||||
-rw-r--r-- | xlators/features/quota/src/quotad.c | 4 |
3 files changed, 7 insertions, 19 deletions
diff --git a/xlators/features/quota/src/quotad-aggregator.c b/xlators/features/quota/src/quotad-aggregator.c index b3ed777c8e2..379bc05af27 100644 --- a/xlators/features/quota/src/quotad-aggregator.c +++ b/xlators/features/quota/src/quotad-aggregator.c @@ -185,11 +185,6 @@ quotad_aggregator_getlimit(rpcsvc_request_t *req) {0}, }; gf_cli_rsp cli_rsp = {0}; - gfs3_lookup_req args = { - { - 0, - }, - }; quotad_aggregator_state_t *state = NULL; xlator_t *this = NULL; dict_t *dict = NULL; @@ -201,6 +196,8 @@ quotad_aggregator_getlimit(rpcsvc_request_t *req) this = THIS; + cli_req.dict.dict_val = alloca(req->msg[0].iov_len); + ret = xdr_to_generic(req->msg[0], &cli_req, (xdrproc_t)xdr_gf_cli_req); if (ret < 0) { // failed to decode msg; @@ -256,12 +253,7 @@ quotad_aggregator_getlimit(rpcsvc_request_t *req) if (ret) goto err; - memcpy(&args.gfid, &gfid, 16); - - args.bname = alloca(req->msg[0].iov_len); - args.xdata.xdata_val = alloca(req->msg[0].iov_len); - - ret = qd_nameless_lookup(this, frame, &args, state->xdata, + ret = qd_nameless_lookup(this, frame, (char *)gfid, state->xdata, quotad_aggregator_getlimit_cbk); if (ret) { cli_rsp.op_errno = ret; @@ -279,9 +271,6 @@ errx: quotad_aggregator_getlimit_cbk(this, frame, &cli_rsp); if (dict) dict_unref(dict); - - if (cli_req.dict.dict_val) - free(cli_req.dict.dict_val); return ret; } @@ -335,7 +324,7 @@ quotad_aggregator_lookup(rpcsvc_request_t *req) GF_PROTOCOL_DICT_UNSERIALIZE(this, state->xdata, (args.xdata.xdata_val), (args.xdata.xdata_len), ret, op_errno, err); - ret = qd_nameless_lookup(this, frame, &args, state->xdata, + ret = qd_nameless_lookup(this, frame, args.gfid, state->xdata, quotad_aggregator_lookup_cbk); if (ret) { rsp.op_errno = ret; @@ -349,7 +338,6 @@ err: rsp.op_errno = op_errno; quotad_aggregator_lookup_cbk(this, frame, &rsp); - free(args.xdata.xdata_val); return ret; } diff --git a/xlators/features/quota/src/quotad-aggregator.h b/xlators/features/quota/src/quotad-aggregator.h index 43f5ddd6e12..318ad7f4995 100644 --- a/xlators/features/quota/src/quotad-aggregator.h +++ b/xlators/features/quota/src/quotad-aggregator.h @@ -28,7 +28,7 @@ typedef struct { typedef int (*quotad_aggregator_lookup_cbk_t)(xlator_t *this, call_frame_t *frame, void *rsp); int -qd_nameless_lookup(xlator_t *this, call_frame_t *frame, gfs3_lookup_req *req, +qd_nameless_lookup(xlator_t *this, call_frame_t *frame, char *gfid, dict_t *xdata, quotad_aggregator_lookup_cbk_t lookup_cbk); int quotad_aggregator_init(xlator_t *this); diff --git a/xlators/features/quota/src/quotad.c b/xlators/features/quota/src/quotad.c index ee1a600e60f..11ef2b1189c 100644 --- a/xlators/features/quota/src/quotad.c +++ b/xlators/features/quota/src/quotad.c @@ -104,7 +104,7 @@ out: } int -qd_nameless_lookup(xlator_t *this, call_frame_t *frame, gfs3_lookup_req *req, +qd_nameless_lookup(xlator_t *this, call_frame_t *frame, char *gfid, dict_t *xdata, quotad_aggregator_lookup_cbk_t lookup_cbk) { gfs3_lookup_rsp rsp = { @@ -128,7 +128,7 @@ qd_nameless_lookup(xlator_t *this, call_frame_t *frame, gfs3_lookup_req *req, goto out; } - memcpy(loc.gfid, req->gfid, 16); + memcpy(loc.gfid, gfid, 16); ret = dict_get_strn(xdata, "volume-uuid", SLEN("volume-uuid"), &volume_uuid); |