From 5c20a688fd2408ff8dcc66fd8ebc935e228dd803 Mon Sep 17 00:00:00 2001 From: Yaniv Kaul Date: Sun, 2 Jun 2019 21:14:18 +0300 Subject: (multiple files) use dict_allocate_and_serialize() where applicable. This function does length, allocation and serialization for you. Change-Id: I142a259952a2fe83dd719442afaefe4a43a8e55e updates: bz#1193929 Signed-off-by: Yaniv Kaul --- xlators/protocol/server/src/server-helpers.c | 27 ++++----------------------- 1 file changed, 4 insertions(+), 23 deletions(-) (limited to 'xlators/protocol/server/src/server-helpers.c') diff --git a/xlators/protocol/server/src/server-helpers.c b/xlators/protocol/server/src/server-helpers.c index 5ffd5d24180..510dd09c268 100644 --- a/xlators/protocol/server/src/server-helpers.c +++ b/xlators/protocol/server/src/server-helpers.c @@ -899,7 +899,6 @@ serialize_rsp_direntp(gf_dirent_t *entries, gfs3_readdirp_rsp *rsp) gfs3_dirplist *trav = NULL; gfs3_dirplist *prev = NULL; int ret = -1; - int temp = 0; GF_VALIDATE_OR_GOTO("server", entries, out); GF_VALIDATE_OR_GOTO("server", rsp, out); @@ -920,28 +919,10 @@ serialize_rsp_direntp(gf_dirent_t *entries, gfs3_readdirp_rsp *rsp) /* if 'dict' is present, pack it */ if (entry->dict) { - temp = dict_serialized_length(entry->dict); - - if (temp < 0) { - gf_msg(THIS->name, GF_LOG_ERROR, EINVAL, PS_MSG_INVALID_ENTRY, - "failed to get " - "serialized length of reply dict"); - errno = EINVAL; - trav->dict.dict_len = 0; - goto out; - } - trav->dict.dict_len = temp; - - trav->dict.dict_val = GF_CALLOC(1, trav->dict.dict_len, - gf_server_mt_rsp_buf_t); - if (!trav->dict.dict_val) { - errno = ENOMEM; - trav->dict.dict_len = 0; - goto out; - } - - ret = dict_serialize(entry->dict, trav->dict.dict_val); - if (ret < 0) { + ret = dict_allocate_and_serialize(entry->dict, + (char **)&trav->dict.dict_val, + &trav->dict.dict_len); + if (ret != 0) { gf_msg(THIS->name, GF_LOG_ERROR, 0, PS_MSG_DICT_SERIALIZE_FAIL, "failed to serialize reply dict"); errno = -ret; -- cgit