74096c
From aa215163cb7d806dc98bef2386a4e282a5e54a31 Mon Sep 17 00:00:00 2001
74096c
From: Atin Mukherjee <amukherj@redhat.com>
74096c
Date: Thu, 25 Apr 2019 12:00:52 +0530
74096c
Subject: [PATCH 432/449] glusterd: Fix coverity defects & put coverity
74096c
 annotations
74096c
74096c
Along with fixing few defect, put the required annotations for the defects which
74096c
are marked ignore/false positive/intentional as per the coverity defect sheet.
74096c
This should avoid the per component graph showing many defects as open in the
74096c
coverity glusterfs web page.
74096c
74096c
> upstream patch link: https://review.gluster.org/#/c/glusterfs/+/22619/
74096c
> Updates: bz#789278
74096c
> Change-Id: I19461dc3603a3bd8f88866a1ab3db43d783af8e4
74096c
> Signed-off-by: Atin Mukherjee <amukherj@redhat.com>
74096c
74096c
BUG: 1787310
74096c
Change-Id: I19461dc3603a3bd8f88866a1ab3db43d783af8e4
74096c
Signed-off-by: Sanju Rakonde <srakonde@redhat.com>
74096c
Reviewed-on: https://code.engineering.redhat.com/gerrit/202631
74096c
Tested-by: RHGS Build Bot <nigelb@redhat.com>
74096c
Reviewed-by: Sunil Kumar Heggodu Gopala Acharya <sheggodu@redhat.com>
74096c
---
74096c
 xlators/mgmt/glusterd/src/glusterd-brick-ops.c     |  7 +++--
74096c
 xlators/mgmt/glusterd/src/glusterd-geo-rep.c       |  3 +-
74096c
 .../glusterd/src/glusterd-gfproxyd-svc-helper.c    |  2 +-
74096c
 xlators/mgmt/glusterd/src/glusterd-handler.c       |  8 ++++-
74096c
 xlators/mgmt/glusterd/src/glusterd-mountbroker.c   |  5 ++-
74096c
 xlators/mgmt/glusterd/src/glusterd-op-sm.c         |  8 +++++
74096c
 xlators/mgmt/glusterd/src/glusterd-peer-utils.c    |  2 ++
74096c
 xlators/mgmt/glusterd/src/glusterd-server-quorum.c |  1 +
74096c
 xlators/mgmt/glusterd/src/glusterd-store.c         |  4 ---
74096c
 xlators/mgmt/glusterd/src/glusterd-svc-helper.c    |  4 +--
74096c
 xlators/mgmt/glusterd/src/glusterd-syncop.c        |  1 +
74096c
 .../mgmt/glusterd/src/glusterd-tierd-svc-helper.c  |  4 +--
74096c
 xlators/mgmt/glusterd/src/glusterd-utils.c         |  9 ++++--
74096c
 xlators/mgmt/glusterd/src/glusterd-volgen.c        | 36 +++++++++++++---------
74096c
 14 files changed, 63 insertions(+), 31 deletions(-)
74096c
74096c
diff --git a/xlators/mgmt/glusterd/src/glusterd-brick-ops.c b/xlators/mgmt/glusterd/src/glusterd-brick-ops.c
74096c
index d424f31..121346c 100644
74096c
--- a/xlators/mgmt/glusterd/src/glusterd-brick-ops.c
74096c
+++ b/xlators/mgmt/glusterd/src/glusterd-brick-ops.c
74096c
@@ -2032,7 +2032,6 @@ glusterd_op_stage_remove_brick(dict_t *dict, char **op_errstr)
74096c
         case GF_OP_CMD_STATUS:
74096c
             ret = 0;
74096c
             goto out;
74096c
-
74096c
         case GF_OP_CMD_DETACH_START:
74096c
             if (volinfo->type != GF_CLUSTER_TYPE_TIER) {
74096c
                 snprintf(msg, sizeof(msg),
74096c
@@ -2044,7 +2043,7 @@ glusterd_op_stage_remove_brick(dict_t *dict, char **op_errstr)
74096c
                        errstr);
74096c
                 goto out;
74096c
             }
74096c
-
74096c
+        /* Fall through */
74096c
         case GF_OP_CMD_START: {
74096c
             if ((volinfo->type == GF_CLUSTER_TYPE_REPLICATE) &&
74096c
                 dict_getn(dict, "replica-count", SLEN("replica-count"))) {
74096c
@@ -2259,7 +2258,8 @@ out:
74096c
         if (op_errstr)
74096c
             *op_errstr = errstr;
74096c
     }
74096c
-
74096c
+    if (!op_errstr && errstr)
74096c
+        GF_FREE(errstr);
74096c
     return ret;
74096c
 }
74096c
 
74096c
@@ -2687,6 +2687,7 @@ glusterd_op_remove_brick(dict_t *dict, char **op_errstr)
74096c
              * Update defrag_cmd as well or it will only be done
74096c
              * for nodes on which the brick to be removed exists.
74096c
              */
74096c
+            /* coverity[MIXED_ENUMS] */
74096c
             volinfo->rebal.defrag_cmd = cmd;
74096c
             volinfo->rebal.defrag_status = GF_DEFRAG_STATUS_NOT_STARTED;
74096c
             ret = dict_get_strn(dict, GF_REMOVE_BRICK_TID_KEY,
74096c
diff --git a/xlators/mgmt/glusterd/src/glusterd-geo-rep.c b/xlators/mgmt/glusterd/src/glusterd-geo-rep.c
74096c
index 85c06c1..5a91df4 100644
74096c
--- a/xlators/mgmt/glusterd/src/glusterd-geo-rep.c
74096c
+++ b/xlators/mgmt/glusterd/src/glusterd-geo-rep.c
74096c
@@ -4107,6 +4107,7 @@ gd_pause_or_resume_gsync(dict_t *dict, char *master, char *slave,
74096c
 
74096c
 out:
74096c
     sys_close(pfd);
74096c
+    /* coverity[INTEGER_OVERFLOW] */
74096c
     return ret;
74096c
 }
74096c
 
74096c
@@ -4183,7 +4184,7 @@ stop_gsync(char *master, char *slave, char **msg, char *conf_path,
74096c
 
74096c
 out:
74096c
     sys_close(pfd);
74096c
-
74096c
+    /* coverity[INTEGER_OVERFLOW] */
74096c
     return ret;
74096c
 }
74096c
 
74096c
diff --git a/xlators/mgmt/glusterd/src/glusterd-gfproxyd-svc-helper.c b/xlators/mgmt/glusterd/src/glusterd-gfproxyd-svc-helper.c
74096c
index 67e3f41..e338bf4 100644
74096c
--- a/xlators/mgmt/glusterd/src/glusterd-gfproxyd-svc-helper.c
74096c
+++ b/xlators/mgmt/glusterd/src/glusterd-gfproxyd-svc-helper.c
74096c
@@ -111,7 +111,7 @@ glusterd_svc_get_gfproxyd_volfile(glusterd_volinfo_t *volinfo, char *svc_name,
74096c
         goto out;
74096c
     }
74096c
 
74096c
-    /* coverity[secure_temp] mkstemp uses 0600 as the mode and is safe */
74096c
+    /* coverity[SECURE_TEMP] mkstemp uses 0600 as the mode and is safe */
74096c
     tmp_fd = mkstemp(*tmpvol);
74096c
     if (tmp_fd < 0) {
74096c
         gf_msg("glusterd", GF_LOG_WARNING, errno, GD_MSG_FILE_OP_FAILED,
74096c
diff --git a/xlators/mgmt/glusterd/src/glusterd-handler.c b/xlators/mgmt/glusterd/src/glusterd-handler.c
74096c
index 2e73c98..1f31e72 100644
74096c
--- a/xlators/mgmt/glusterd/src/glusterd-handler.c
74096c
+++ b/xlators/mgmt/glusterd/src/glusterd-handler.c
74096c
@@ -930,6 +930,7 @@ __glusterd_handle_cluster_lock(rpcsvc_request_t *req)
74096c
 
74096c
     op_ctx = dict_new();
74096c
     if (!op_ctx) {
74096c
+        ret = -1;
74096c
         gf_msg(this->name, GF_LOG_ERROR, ENOMEM, GD_MSG_DICT_CREATE_FAIL,
74096c
                "Unable to set new dict");
74096c
         goto out;
74096c
@@ -956,6 +957,9 @@ out:
74096c
     glusterd_friend_sm();
74096c
     glusterd_op_sm();
74096c
 
74096c
+    if (ret)
74096c
+        GF_FREE(ctx);
74096c
+
74096c
     return ret;
74096c
 }
74096c
 
74096c
@@ -3470,6 +3474,7 @@ glusterd_rpc_create(struct rpc_clnt **rpc, dict_t *options,
74096c
     GF_ASSERT(this);
74096c
 
74096c
     GF_ASSERT(options);
74096c
+    GF_VALIDATE_OR_GOTO(this->name, rpc, out);
74096c
 
74096c
     if (force && rpc && *rpc) {
74096c
         (void)rpc_clnt_unref(*rpc);
74096c
@@ -3482,7 +3487,6 @@ glusterd_rpc_create(struct rpc_clnt **rpc, dict_t *options,
74096c
         goto out;
74096c
 
74096c
     ret = rpc_clnt_register_notify(new_rpc, notify_fn, notify_data);
74096c
-    *rpc = new_rpc;
74096c
     if (ret)
74096c
         goto out;
74096c
     ret = rpc_clnt_start(new_rpc);
74096c
@@ -3491,6 +3495,8 @@ out:
74096c
         if (new_rpc) {
74096c
             (void)rpc_clnt_unref(new_rpc);
74096c
         }
74096c
+    } else {
74096c
+        *rpc = new_rpc;
74096c
     }
74096c
 
74096c
     gf_msg_debug(this->name, 0, "returning %d", ret);
74096c
diff --git a/xlators/mgmt/glusterd/src/glusterd-mountbroker.c b/xlators/mgmt/glusterd/src/glusterd-mountbroker.c
74096c
index 332ddef..c017ccb 100644
74096c
--- a/xlators/mgmt/glusterd/src/glusterd-mountbroker.c
74096c
+++ b/xlators/mgmt/glusterd/src/glusterd-mountbroker.c
74096c
@@ -334,7 +334,10 @@ make_ghadoop_mountspec(gf_mount_spec_t *mspec, const char *volname, char *user,
74096c
     if (ret == -1)
74096c
         return ret;
74096c
 
74096c
-    return parse_mount_pattern_desc(mspec, hadoop_mnt_desc);
74096c
+    ret = parse_mount_pattern_desc(mspec, hadoop_mnt_desc);
74096c
+    GF_FREE(hadoop_mnt_desc);
74096c
+
74096c
+    return ret;
74096c
 }
74096c
 
74096c
 static gf_boolean_t
74096c
diff --git a/xlators/mgmt/glusterd/src/glusterd-op-sm.c b/xlators/mgmt/glusterd/src/glusterd-op-sm.c
74096c
index 6475611..46fc607 100644
74096c
--- a/xlators/mgmt/glusterd/src/glusterd-op-sm.c
74096c
+++ b/xlators/mgmt/glusterd/src/glusterd-op-sm.c
74096c
@@ -2467,6 +2467,7 @@ glusterd_start_bricks(glusterd_volinfo_t *volinfo)
74096c
         if (!brickinfo->start_triggered) {
74096c
             pthread_mutex_lock(&brickinfo->restart_mutex);
74096c
             {
74096c
+                /* coverity[SLEEP] */
74096c
                 ret = glusterd_brick_start(volinfo, brickinfo, _gf_false,
74096c
                                            _gf_false);
74096c
             }
74096c
@@ -3466,6 +3467,7 @@ _add_task_to_dict(dict_t *dict, glusterd_volinfo_t *volinfo, int op, int index)
74096c
 
74096c
     switch (op) {
74096c
         case GD_OP_REMOVE_TIER_BRICK:
74096c
+        /* Fall through */
74096c
         case GD_OP_REMOVE_BRICK:
74096c
             snprintf(key, sizeof(key), "task%d", index);
74096c
             ret = _add_remove_bricks_to_dict(dict, volinfo, key);
74096c
@@ -7550,6 +7552,7 @@ glusterd_op_ac_send_brick_op(glusterd_op_sm_event_t *event, void *ctx)
74096c
     glusterd_op_t op = GD_OP_NONE;
74096c
     glusterd_req_ctx_t *req_ctx = NULL;
74096c
     char *op_errstr = NULL;
74096c
+    gf_boolean_t free_req_ctx = _gf_false;
74096c
 
74096c
     this = THIS;
74096c
     priv = this->private;
74096c
@@ -7558,6 +7561,9 @@ glusterd_op_ac_send_brick_op(glusterd_op_sm_event_t *event, void *ctx)
74096c
         req_ctx = ctx;
74096c
     } else {
74096c
         req_ctx = GF_CALLOC(1, sizeof(*req_ctx), gf_gld_mt_op_allack_ctx_t);
74096c
+        if (!req_ctx)
74096c
+            goto out;
74096c
+        free_req_ctx = _gf_true;
74096c
         op = glusterd_op_get_op();
74096c
         req_ctx->op = op;
74096c
         gf_uuid_copy(req_ctx->uuid, MY_UUID);
74096c
@@ -7588,6 +7594,8 @@ glusterd_op_ac_send_brick_op(glusterd_op_sm_event_t *event, void *ctx)
74096c
     }
74096c
 
74096c
 out:
74096c
+    if (ret && req_ctx && free_req_ctx)
74096c
+        GF_FREE(req_ctx);
74096c
     gf_msg_debug(this->name, 0, "Returning with %d", ret);
74096c
 
74096c
     return ret;
74096c
diff --git a/xlators/mgmt/glusterd/src/glusterd-peer-utils.c b/xlators/mgmt/glusterd/src/glusterd-peer-utils.c
74096c
index 8c1feeb..1a65359 100644
74096c
--- a/xlators/mgmt/glusterd/src/glusterd-peer-utils.c
74096c
+++ b/xlators/mgmt/glusterd/src/glusterd-peer-utils.c
74096c
@@ -82,6 +82,7 @@ glusterd_peerinfo_cleanup(glusterd_peerinfo_t *peerinfo)
74096c
     call_rcu(&peerinfo->rcu_head.head, glusterd_peerinfo_destroy);
74096c
 
74096c
     if (quorum_action)
74096c
+        /* coverity[SLEEP] */
74096c
         glusterd_do_quorum_action();
74096c
     return 0;
74096c
 }
74096c
@@ -358,6 +359,7 @@ glusterd_uuid_to_hostname(uuid_t uuid)
74096c
 
74096c
     if (!gf_uuid_compare(MY_UUID, uuid)) {
74096c
         hostname = gf_strdup("localhost");
74096c
+        return hostname;
74096c
     }
74096c
     RCU_READ_LOCK;
74096c
     if (!cds_list_empty(&priv->peers)) {
74096c
diff --git a/xlators/mgmt/glusterd/src/glusterd-server-quorum.c b/xlators/mgmt/glusterd/src/glusterd-server-quorum.c
74096c
index fd334e6..f378187 100644
74096c
--- a/xlators/mgmt/glusterd/src/glusterd-server-quorum.c
74096c
+++ b/xlators/mgmt/glusterd/src/glusterd-server-quorum.c
74096c
@@ -372,6 +372,7 @@ glusterd_do_volume_quorum_action(xlator_t *this, glusterd_volinfo_t *volinfo,
74096c
             if (!brickinfo->start_triggered) {
74096c
                 pthread_mutex_lock(&brickinfo->restart_mutex);
74096c
                 {
74096c
+                    /* coverity[SLEEP] */
74096c
                     ret = glusterd_brick_start(volinfo, brickinfo, _gf_false,
74096c
                                                _gf_false);
74096c
                 }
74096c
diff --git a/xlators/mgmt/glusterd/src/glusterd-store.c b/xlators/mgmt/glusterd/src/glusterd-store.c
74096c
index b3b5ee9..4fa8116 100644
74096c
--- a/xlators/mgmt/glusterd/src/glusterd-store.c
74096c
+++ b/xlators/mgmt/glusterd/src/glusterd-store.c
74096c
@@ -4764,10 +4764,6 @@ glusterd_store_retrieve_peers(xlator_t *this)
74096c
          */
74096c
         address = cds_list_entry(peerinfo->hostnames.next,
74096c
                                  glusterd_peer_hostname_t, hostname_list);
74096c
-        if (!address) {
74096c
-            ret = -1;
74096c
-            goto next;
74096c
-        }
74096c
         peerinfo->hostname = gf_strdup(address->hostname);
74096c
 
74096c
         ret = glusterd_friend_add_from_peerinfo(peerinfo, 1, NULL);
74096c
diff --git a/xlators/mgmt/glusterd/src/glusterd-svc-helper.c b/xlators/mgmt/glusterd/src/glusterd-svc-helper.c
74096c
index ca19a75..1d1f42d 100644
74096c
--- a/xlators/mgmt/glusterd/src/glusterd-svc-helper.c
74096c
+++ b/xlators/mgmt/glusterd/src/glusterd-svc-helper.c
74096c
@@ -179,7 +179,7 @@ glusterd_svc_check_volfile_identical(char *svc_name,
74096c
         goto out;
74096c
     }
74096c
 
74096c
-    /* coverity[secure_temp] mkstemp uses 0600 as the mode and is safe */
74096c
+    /* coverity[SECURE_TEMP] mkstemp uses 0600 as the mode and is safe */
74096c
     tmp_fd = mkstemp(tmpvol);
74096c
     if (tmp_fd < 0) {
74096c
         gf_msg(this->name, GF_LOG_WARNING, errno, GD_MSG_FILE_OP_FAILED,
74096c
@@ -241,7 +241,7 @@ glusterd_svc_check_topology_identical(char *svc_name,
74096c
         goto out;
74096c
     }
74096c
 
74096c
-    /* coverity[secure_temp] mkstemp uses 0600 as the mode and is safe */
74096c
+    /* coverity[SECURE_TEMP] mkstemp uses 0600 as the mode and is safe */
74096c
     tmpfd = mkstemp(tmpvol);
74096c
     if (tmpfd < 0) {
74096c
         gf_msg(this->name, GF_LOG_WARNING, errno, GD_MSG_FILE_OP_FAILED,
74096c
diff --git a/xlators/mgmt/glusterd/src/glusterd-syncop.c b/xlators/mgmt/glusterd/src/glusterd-syncop.c
74096c
index 618d8bc..9e47d14 100644
74096c
--- a/xlators/mgmt/glusterd/src/glusterd-syncop.c
74096c
+++ b/xlators/mgmt/glusterd/src/glusterd-syncop.c
74096c
@@ -1752,6 +1752,7 @@ gd_brick_op_phase(glusterd_op_t op, dict_t *op_ctx, dict_t *req_dict,
74096c
                 if (dict_get(op_ctx, "client-count"))
74096c
                     break;
74096c
             }
74096c
+            /* coverity[MIXED_ENUMS] */
74096c
         } else if (cmd == GF_OP_CMD_DETACH_START) {
74096c
             op = GD_OP_REMOVE_BRICK;
74096c
             dict_del(req_dict, "rebalance-command");
74096c
diff --git a/xlators/mgmt/glusterd/src/glusterd-tierd-svc-helper.c b/xlators/mgmt/glusterd/src/glusterd-tierd-svc-helper.c
74096c
index 922eae7..59843a0 100644
74096c
--- a/xlators/mgmt/glusterd/src/glusterd-tierd-svc-helper.c
74096c
+++ b/xlators/mgmt/glusterd/src/glusterd-tierd-svc-helper.c
74096c
@@ -116,7 +116,7 @@ glusterd_svc_check_tier_volfile_identical(char *svc_name,
74096c
         goto out;
74096c
     }
74096c
 
74096c
-    /* coverity[secure_temp] mkstemp uses 0600 as the mode and is safe */
74096c
+    /* coverity[SECURE_TEMP] mkstemp uses 0600 as the mode and is safe */
74096c
     tmp_fd = mkstemp(tmpvol);
74096c
     if (tmp_fd < 0) {
74096c
         gf_msg(this->name, GF_LOG_WARNING, errno, GD_MSG_FILE_OP_FAILED,
74096c
@@ -177,7 +177,7 @@ glusterd_svc_check_tier_topology_identical(char *svc_name,
74096c
         goto out;
74096c
     }
74096c
 
74096c
-    /* coverity[secure_temp] mkstemp uses 0600 as the mode and is safe */
74096c
+    /* coverity[SECURE_TEMP] mkstemp uses 0600 as the mode and is safe */
74096c
     tmpfd = mkstemp(tmpvol);
74096c
     if (tmpfd < 0) {
74096c
         gf_msg(this->name, GF_LOG_WARNING, errno, GD_MSG_FILE_OP_FAILED,
74096c
diff --git a/xlators/mgmt/glusterd/src/glusterd-utils.c b/xlators/mgmt/glusterd/src/glusterd-utils.c
74096c
index 14e23d1..8b0fc9a 100644
74096c
--- a/xlators/mgmt/glusterd/src/glusterd-utils.c
74096c
+++ b/xlators/mgmt/glusterd/src/glusterd-utils.c
74096c
@@ -908,6 +908,7 @@ glusterd_create_sub_tier_volinfo(glusterd_volinfo_t *volinfo,
74096c
         (*dup_volinfo)->brick_count = tier_info->cold_brick_count;
74096c
     }
74096c
 out:
74096c
+    /* coverity[REVERSE_NULL] */
74096c
     if (ret && *dup_volinfo) {
74096c
         glusterd_volinfo_delete(*dup_volinfo);
74096c
         *dup_volinfo = NULL;
74096c
@@ -2738,6 +2739,7 @@ glusterd_readin_file(const char *filepath, int *line_count)
74096c
     /* Reduce allocation to minimal size.  */
74096c
     p = GF_REALLOC(lines, (counter + 1) * sizeof(char *));
74096c
     if (!p) {
74096c
+        /* coverity[TAINTED_SCALAR] */
74096c
         free_lines(lines, counter);
74096c
         lines = NULL;
74096c
         goto out;
74096c
@@ -6782,6 +6784,7 @@ glusterd_restart_bricks(void *opaque)
74096c
                 if (!brickinfo->start_triggered) {
74096c
                     pthread_mutex_lock(&brickinfo->restart_mutex);
74096c
                     {
74096c
+                        /* coverity[SLEEP] */
74096c
                         glusterd_brick_start(volinfo, brickinfo, _gf_false,
74096c
                                              _gf_false);
74096c
                     }
74096c
@@ -8886,7 +8889,7 @@ glusterd_nfs_statedump(char *options, int option_cnt, char **op_errstr)
74096c
     kill(pid, SIGUSR1);
74096c
 
74096c
     sleep(1);
74096c
-
74096c
+    /* coverity[TAINTED_STRING] */
74096c
     sys_unlink(dumpoptions_path);
74096c
     ret = 0;
74096c
 out:
74096c
@@ -9012,6 +9015,7 @@ glusterd_quotad_statedump(char *options, int option_cnt, char **op_errstr)
74096c
 
74096c
     sleep(1);
74096c
 
74096c
+    /* coverity[TAINTED_STRING] */
74096c
     sys_unlink(dumpoptions_path);
74096c
     ret = 0;
74096c
 out:
74096c
@@ -13423,7 +13427,7 @@ glusterd_get_global_options_for_all_vols(rpcsvc_request_t *req, dict_t *ctx,
74096c
         if (key_fixed)
74096c
             key = key_fixed;
74096c
     }
74096c
-
74096c
+    /* coverity[CONSTANT_EXPRESSION_RESULT] */
74096c
     ALL_VOLUME_OPTION_CHECK("all", _gf_true, key, ret, op_errstr, out);
74096c
 
74096c
     for (i = 0; valid_all_vol_opts[i].option; i++) {
74096c
@@ -14153,6 +14157,7 @@ glusterd_disallow_op_for_tier(glusterd_volinfo_t *volinfo, glusterd_op_t op,
74096c
             break;
74096c
         case GD_OP_REMOVE_BRICK:
74096c
             switch (cmd) {
74096c
+                /* coverity[MIXED_ENUMS] */
74096c
                 case GF_DEFRAG_CMD_DETACH_START:
74096c
                 case GF_OP_CMD_DETACH_COMMIT_FORCE:
74096c
                 case GF_OP_CMD_DETACH_COMMIT:
74096c
diff --git a/xlators/mgmt/glusterd/src/glusterd-volgen.c b/xlators/mgmt/glusterd/src/glusterd-volgen.c
74096c
index 539e8a5..6852f8e 100644
74096c
--- a/xlators/mgmt/glusterd/src/glusterd-volgen.c
74096c
+++ b/xlators/mgmt/glusterd/src/glusterd-volgen.c
74096c
@@ -322,7 +322,7 @@ volopt_trie_cbk(char *word, void *param)
74096c
 }
74096c
 
74096c
 static int
74096c
-process_nodevec(struct trienodevec *nodevec, char **hint)
74096c
+process_nodevec(struct trienodevec *nodevec, char **outputhint, char *inputhint)
74096c
 {
74096c
     int ret = 0;
74096c
     char *hint1 = NULL;
74096c
@@ -331,14 +331,14 @@ process_nodevec(struct trienodevec *nodevec, char **hint)
74096c
     trienode_t **nodes = nodevec->nodes;
74096c
 
74096c
     if (!nodes[0]) {
74096c
-        *hint = NULL;
74096c
+        *outputhint = NULL;
74096c
         return 0;
74096c
     }
74096c
 
74096c
 #if 0
74096c
         /* Limit as in git */
74096c
         if (trienode_get_dist (nodes[0]) >= 6) {
74096c
-                *hint = NULL;
74096c
+                *outputhint = NULL;
74096c
                 return 0;
74096c
         }
74096c
 #endif
74096c
@@ -347,23 +347,30 @@ process_nodevec(struct trienodevec *nodevec, char **hint)
74096c
         return -1;
74096c
 
74096c
     if (nodevec->cnt < 2 || !nodes[1]) {
74096c
-        *hint = hint1;
74096c
+        *outputhint = hint1;
74096c
         return 0;
74096c
     }
74096c
 
74096c
-    if (trienode_get_word(nodes[1], &hint2))
74096c
+    if (trienode_get_word(nodes[1], &hint2)) {
74096c
+        GF_FREE(hint1);
74096c
         return -1;
74096c
+    }
74096c
 
74096c
-    if (*hint)
74096c
-        hintinfx = *hint;
74096c
-    ret = gf_asprintf(hint, "%s or %s%s", hint1, hintinfx, hint2);
74096c
+    if (inputhint)
74096c
+        hintinfx = inputhint;
74096c
+    ret = gf_asprintf(outputhint, "%s or %s%s", hint1, hintinfx, hint2);
74096c
     if (ret > 0)
74096c
         ret = 0;
74096c
+    if (hint1)
74096c
+        GF_FREE(hint1);
74096c
+    if (hint2)
74096c
+        GF_FREE(hint2);
74096c
     return ret;
74096c
 }
74096c
 
74096c
 static int
74096c
-volopt_trie_section(int lvl, char **patt, char *word, char **hint, int hints)
74096c
+volopt_trie_section(int lvl, char **patt, char *word, char **outputhint,
74096c
+                    char *inputhint, int hints)
74096c
 {
74096c
     trienode_t *nodes[] = {NULL, NULL};
74096c
     struct trienodevec nodevec = {nodes, 2};
74096c
@@ -384,7 +391,7 @@ volopt_trie_section(int lvl, char **patt, char *word, char **hint, int hints)
74096c
     nodevec.cnt = hints;
74096c
     ret = trie_measure_vec(trie, word, &nodevec);
74096c
     if (!ret && nodevec.nodes[0])
74096c
-        ret = process_nodevec(&nodevec, hint);
74096c
+        ret = process_nodevec(&nodevec, outputhint, inputhint);
74096c
 
74096c
     trie_destroy(trie);
74096c
 
74096c
@@ -396,6 +403,7 @@ volopt_trie(char *key, char **hint)
74096c
 {
74096c
     char *patt[] = {NULL};
74096c
     char *fullhint = NULL;
74096c
+    char *inputhint = NULL;
74096c
     char *dot = NULL;
74096c
     char *dom = NULL;
74096c
     int len = 0;
74096c
@@ -405,7 +413,7 @@ volopt_trie(char *key, char **hint)
74096c
 
74096c
     dot = strchr(key, '.');
74096c
     if (!dot)
74096c
-        return volopt_trie_section(1, patt, key, hint, 2);
74096c
+        return volopt_trie_section(1, patt, key, hint, inputhint, 2);
74096c
 
74096c
     len = dot - key;
74096c
     dom = gf_strdup(key);
74096c
@@ -413,7 +421,7 @@ volopt_trie(char *key, char **hint)
74096c
         return -1;
74096c
     dom[len] = '\0';
74096c
 
74096c
-    ret = volopt_trie_section(0, NULL, dom, patt, 1);
74096c
+    ret = volopt_trie_section(0, NULL, dom, patt, inputhint, 1);
74096c
     GF_FREE(dom);
74096c
     if (ret) {
74096c
         patt[0] = NULL;
74096c
@@ -422,8 +430,8 @@ volopt_trie(char *key, char **hint)
74096c
     if (!patt[0])
74096c
         goto out;
74096c
 
74096c
-    *hint = "...";
74096c
-    ret = volopt_trie_section(1, patt, dot + 1, hint, 2);
74096c
+    inputhint = "...";
74096c
+    ret = volopt_trie_section(1, patt, dot + 1, hint, inputhint, 2);
74096c
     if (ret)
74096c
         goto out;
74096c
     if (*hint) {
74096c
-- 
74096c
1.8.3.1
74096c