]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
global: Use T_END_PASS_STR() where possible
authorTimo Sirainen <timo.sirainen@open-xchange.com>
Mon, 16 Nov 2020 17:37:26 +0000 (19:37 +0200)
committeraki.tuomi <aki.tuomi@open-xchange.com>
Tue, 4 May 2021 07:02:35 +0000 (07:02 +0000)
src/config/config-parser.c
src/lib-fs/fs-api.c
src/lib-imap/imap-bodystructure.c
src/lib-mail/mail-user-hash.c
src/lib-mail/message-search.c
src/lib-settings/settings-parser.c
src/lib-sql/driver-cassandra.c
src/lib-sql/driver-sqlpool.c

index 47d0f18fd2139ab420c1bc849563352816c35485..0a0df795cfb6ca68d2019434bb84595a5ba387a5 100644 (file)
@@ -362,8 +362,7 @@ config_filter_parser_check(struct config_parser_context *ctx,
                           const struct config_module_parser *p,
                           const char **error_r)
 {
-       const char *error;
-       char *error_dup = NULL;
+       const char *error = NULL;
        bool ok;
 
        for (; p->root != NULL; p++) {
@@ -375,13 +374,11 @@ config_filter_parser_check(struct config_parser_context *ctx,
                settings_parse_var_skip(p->parser);
                T_BEGIN {
                        ok = settings_parser_check(p->parser, ctx->pool, &error);
-                       if (!ok)
-                               error_dup = i_strdup(error);
-               } T_END;
+               } T_END_PASS_STR_IF(!ok, &error);
                if (!ok) {
-                       i_assert(error_dup != NULL);
-                       *error_r = t_strdup(error_dup);
-                       i_free(error_dup);
+                       /* be sure to assert-crash early if error is missing */
+                       i_assert(error != NULL);
+                       *error_r = error;
                        return -1;
                }
        }
index cac183bef716ba5b2fd6aba05d2c4c203913bfa7..d9bb4bd5c1f7880cfcefcf1d5ac7d1d5b8162699 100644 (file)
@@ -41,8 +41,7 @@ fs_alloc(const struct fs *fs_class, const char *args,
         const struct fs_settings *set, struct fs **fs_r, const char **error_r)
 {
        struct fs *fs;
-       const char *temp_error;
-       char *error = NULL;
+       const char *error;
        int ret;
 
        fs = fs_class->v.alloc();
@@ -54,15 +53,13 @@ fs_alloc(const struct fs *fs_class, const char *args,
        event_set_forced_debug(fs->event, fs->set.debug);
 
        T_BEGIN {
-               if ((ret = fs_class->v.init(fs, args, set, &temp_error)) < 0)
-                       error = i_strdup(temp_error);
-       } T_END;
+               ret = fs_class->v.init(fs, args, set, &error);
+       } T_END_PASS_STR_IF(ret < 0, &error);
        if (ret < 0) {
                /* a bit kludgy way to allow data stack frame usage in normal
                   conditions but still be able to return error message from
                   data stack. */
                *error_r = t_strdup_printf("%s: %s", fs_class->name, error);
-               i_free(error);
                fs_unref(&fs);
                return -1;
        }
index 82028db6546b791180e528d565a127afc1a38a21..522c2500676283d70cd0bbc3cb95ca44f4bebd2e 100644 (file)
@@ -687,7 +687,6 @@ int imap_bodystructure_parse_full(const char *bodystructure,
        struct istream *input;
        struct imap_parser *parser;
        const struct imap_arg *args;
-       char *error = NULL;
        int ret;
 
        i_assert(*parts == NULL || (*parts)->next == NULL);
@@ -708,14 +707,7 @@ int imap_bodystructure_parse_full(const char *bodystructure,
                T_BEGIN {
                        ret = imap_bodystructure_parse_args
                                (args, pool, parts, error_r);
-                       if (ret < 0)
-                               error = i_strdup(*error_r);
-               } T_END;
-
-               if (ret < 0) {
-                       *error_r = t_strdup(error);
-                       i_free(error);
-               }
+               } T_END_PASS_STR_IF(ret < 0, error_r);
        }
 
        imap_parser_unref(&parser);
index 0838b9ecb81d6f08602ba0e10f4d01d79d195d44..88724a657d9735453d11898b927f6ef1b8f25e22 100644 (file)
@@ -11,7 +11,6 @@ bool mail_user_hash(const char *username, const char *format,
 {
        unsigned char md5[MD5_RESULTLEN];
        unsigned int i, hash = 0;
-       char *error_dup = NULL;
        int ret = 1;
 
        if (strcmp(format, "%u") == 0) {
@@ -31,14 +30,11 @@ bool mail_user_hash(const char *username, const char *format,
                        { '\0', NULL, NULL }
                };
                string_t *str = t_str_new(128);
-               const char *error;
 
-               ret = var_expand(str, format, tab, &error);
+               ret = var_expand(str, format, tab, error_r);
                i_assert(ret >= 0);
-               if (ret == 0)
-                       error_dup = i_strdup(error);
                md5_get_digest(str_data(str), str_len(str), md5);
-       } T_END;
+       } T_END_PASS_STR_IF(ret == 0, error_r);
        for (i = 0; i < sizeof(hash); i++)
                hash = (hash << CHAR_BIT) | md5[i];
        if (hash == 0) {
@@ -48,7 +44,5 @@ bool mail_user_hash(const char *username, const char *format,
                hash = 1;
        }
        *hash_r = hash;
-       *error_r = t_strdup(error_dup);
-       i_free(error_dup);
        return ret > 0;
 }
index 14d1a11470889dfc924f56ad148e7f11352224b5..5f54485339af07385ab8845eb0d464addfc10cee 100644 (file)
@@ -237,14 +237,10 @@ int message_search_msg(struct message_search_context *ctx,
                       struct istream *input, struct message_part *parts,
                       const char **error_r)
 {
-       char *error;
        int ret;
 
        T_BEGIN {
                ret = message_search_msg_real(ctx, input, parts, error_r);
-               error = i_strdup(*error_r);
-       } T_END;
-       *error_r = t_strdup(error);
-       i_free(error);
+       } T_END_PASS_STR_IF(ret < 0, error_r);
        return ret;
 }
index 248330152437cd1eb87d8114959e164424339146..4fc662ba90ae4d4e8c9d70d2c1f8dcab74718581 100644 (file)
@@ -1383,21 +1383,15 @@ int settings_var_expand_with_funcs(const struct setting_parser_info *info,
                                   const struct var_expand_func_table *func_table,
                                   void *func_context, const char **error_r)
 {
-       char *error_dup = NULL;
        int ret;
 
        T_BEGIN {
-               const char *error;
                string_t *str = t_str_new(256);
 
                ret = settings_var_expand_info(info, set, pool, table,
                                               func_table, func_context, str,
-                                              &error);
-               if (ret <= 0)
-                       error_dup = i_strdup(error);
-       } T_END;
-       *error_r = t_strdup(error_dup);
-       i_free(error_dup);
+                                              error_r);
+       } T_END_PASS_STR_IF(ret <= 0, error_r);
        return ret;
 }
 
index 65fcc22ccaeb7c96c7b4041e7129681a5e462041..5b140b4f059733a691c6bdca30d8df19f41268ca 100644 (file)
@@ -997,7 +997,6 @@ static int driver_cassandra_init_full_v(const struct sql_settings *set,
                                        const char **error_r)
 {
        struct cassandra_db *db;
-       char *error = NULL;
        int ret;
 
        db = i_new(struct cassandra_db, 1);
@@ -1008,17 +1007,11 @@ static int driver_cassandra_init_full_v(const struct sql_settings *set,
        event_set_append_log_prefix(db->api.event, "cassandra: ");
 
        T_BEGIN {
-               const char *tmp;
-               if ((ret = driver_cassandra_parse_connect_string(db,
-                                                                set->connect_string,
-                                                                &tmp)) < 0) {
-                       error = i_strdup(tmp);
-               }
-       } T_END;
+               ret = driver_cassandra_parse_connect_string(db,
+                       set->connect_string, error_r);
+       } T_END_PASS_STR_IF(ret < 0, error_r);
 
        if (ret < 0) {
-               *error_r = t_strdup(error);
-               i_free(error);
                driver_cassandra_free(&db);
                return -1;
        }
index 9921bce990f0c5b5a5a59398d682c5618ea81e53..c28db841805ac8a47e155681269bf7fe84d842ed 100644 (file)
@@ -496,7 +496,6 @@ static void sqlpool_add_all_once(struct sqlpool_db *db)
 int driver_sqlpool_init_full(const struct sql_settings *set, const struct sql_db *driver,
                             struct sql_db **db_r, const char **error_r)
 {
-       char *error;
        struct sqlpool_db *db;
        int ret;
 
@@ -511,15 +510,11 @@ int driver_sqlpool_init_full(const struct sql_settings *set, const struct sql_db
        i_array_init(&db->hosts, 8);
 
        T_BEGIN {
-               const char *tmp = NULL;
-               if ((ret = driver_sqlpool_parse_hosts(db, set->connect_string,
-                                                     &tmp)) < 0)
-                       error = i_strdup(tmp);
-       } T_END;
+               ret = driver_sqlpool_parse_hosts(db, set->connect_string,
+                                                error_r);
+       } T_END_PASS_STR_IF(ret < 0, error_r);
 
        if (ret < 0) {
-               *error_r = t_strdup(error);
-               i_free(error);
                driver_sqlpool_deinit(&db->api);
                return ret;
        }