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++) {
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;
}
}
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();
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;
}
struct istream *input;
struct imap_parser *parser;
const struct imap_arg *args;
- char *error = NULL;
int ret;
i_assert(*parts == NULL || (*parts)->next == NULL);
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);
{
unsigned char md5[MD5_RESULTLEN];
unsigned int i, hash = 0;
- char *error_dup = NULL;
int ret = 1;
if (strcmp(format, "%u") == 0) {
{ '\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) {
hash = 1;
}
*hash_r = hash;
- *error_r = t_strdup(error_dup);
- i_free(error_dup);
return ret > 0;
}
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;
}
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;
}
const char **error_r)
{
struct cassandra_db *db;
- char *error = NULL;
int ret;
db = i_new(struct cassandra_db, 1);
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;
}
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;
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;
}