From a9d4d369efc978511e3cb69e5643945710cc9416 Mon Sep 17 00:00:00 2001 From: Krishnan Parthasarathi Date: Wed, 2 Apr 2014 11:36:20 +0530 Subject: dict: add dict_set_dynstr_with_alloc There is an overwhelming no. of instances of the following pattern in glusterd module. ... char *dynstr = gf_strdup (str); if (!dynstr) goto err; ret = dict_set_dynstr (dict, key, dynstr); if (ret) goto err; ... With this changes it would look as below, ret = dict_set_dynstr_with_alloc (dict, key, str); if (ret) goto err; Change-Id: I6a47b1cbab4834badadc48c56d0b5c8c06c6dd4d Signed-off-by: Krishnan Parthasarathi Reviewed-on: http://review.gluster.org/7379 Tested-by: Gluster Build System Reviewed-by: Jeff Darcy --- libglusterfs/src/dict.c | 17 +++++++++++++++++ libglusterfs/src/dict.h | 1 + 2 files changed, 18 insertions(+) (limited to 'libglusterfs') diff --git a/libglusterfs/src/dict.c b/libglusterfs/src/dict.c index 7bc5d57b0..1bed8bf9b 100644 --- a/libglusterfs/src/dict.c +++ b/libglusterfs/src/dict.c @@ -2066,6 +2066,23 @@ err: return ret; } +int +dict_set_dynstr_with_alloc (dict_t *this, char *key, const char *str) +{ + char *alloc_str = NULL; + int ret = -1; + + alloc_str = gf_strdup (str); + if (!alloc_str) + return -1; + + ret = dict_set_dynstr (this, key, alloc_str); + if (ret) + GF_FREE (alloc_str); + + return ret; +} + int dict_set_dynstr (dict_t *this, char *key, char *str) { diff --git a/libglusterfs/src/dict.h b/libglusterfs/src/dict.h index 6e5d8aa06..a92fd2cb6 100644 --- a/libglusterfs/src/dict.h +++ b/libglusterfs/src/dict.h @@ -228,6 +228,7 @@ GF_MUST_CHECK int dict_set_static_bin (dict_t *this, char *key, void *ptr, size_ GF_MUST_CHECK int dict_set_str (dict_t *this, char *key, char *str); GF_MUST_CHECK int dict_set_dynmstr (dict_t *this, char *key, char *str); GF_MUST_CHECK int dict_set_dynstr (dict_t *this, char *key, char *str); +GF_MUST_CHECK int dict_set_dynstr_with_alloc (dict_t *this, char *key, const char *str); GF_MUST_CHECK int dict_get_str (dict_t *this, char *key, char **str); GF_MUST_CHECK int dict_get_str_boolean (dict_t *this, char *key, int default_val); -- cgit