From: Timo Sirainen Date: Mon, 25 Nov 2019 09:06:07 +0000 (+0200) Subject: lib-fs: Change last_error from string_t to char * X-Git-Tag: 2.3.10~222 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=3a51b7529b1f6453a63e92767b41aa7f66cdc0aa;p=thirdparty%2Fdovecot%2Fcore.git lib-fs: Change last_error from string_t to char * The string isn't modified in a way that string_t is useful. This change also allows fs_set_error() parameters to point to previous error string without breaking. --- diff --git a/src/lib-fs/fs-api-private.h b/src/lib-fs/fs-api-private.h index ac813d7116..ac702ba8e4 100644 --- a/src/lib-fs/fs-api-private.h +++ b/src/lib-fs/fs-api-private.h @@ -83,7 +83,7 @@ struct fs { char *username, *session_id; struct fs_settings set; - string_t *last_error; + char *last_error; /* may be used by fs_wait_async() to do the waiting */ struct ioloop *wait_ioloop, *prev_ioloop; diff --git a/src/lib-fs/fs-api.c b/src/lib-fs/fs-api.c index a939f612dc..f5836ec6a1 100644 --- a/src/lib-fs/fs-api.c +++ b/src/lib-fs/fs-api.c @@ -30,7 +30,6 @@ fs_alloc(const struct fs *fs_class, const char *args, fs = fs_class->v.alloc(); fs->refcount = 1; - fs->last_error = str_new(default_pool, 64); fs->set.debug = set->debug; fs->set.enable_timing = set->enable_timing; i_array_init(&fs->module_contexts, 5); @@ -197,14 +196,12 @@ void fs_ref(struct fs *fs) void fs_unref(struct fs **_fs) { struct fs *fs = *_fs; - string_t *last_error; struct array module_contexts_arr; unsigned int i; if (fs == NULL) return; - last_error = fs->last_error; module_contexts_arr = fs->module_contexts.arr; i_assert(fs->refcount > 0); @@ -224,6 +221,7 @@ void fs_unref(struct fs **_fs) i_free(fs->username); i_free(fs->session_id); i_free(fs->temp_path_prefix); + i_free(fs->last_error); for (i = 0; i < FS_OP_COUNT; i++) { if (fs->stats.timings[i] != NULL) stats_dist_deinit(&fs->stats.timings[i]); @@ -232,7 +230,6 @@ void fs_unref(struct fs **_fs) fs->v.deinit(fs); } T_END; array_free_i(&module_contexts_arr); - str_free(&last_error); } struct fs *fs_get_parent(struct fs *fs) @@ -527,8 +524,10 @@ fs_set_verror(struct fs *fs, const char *fmt, va_list args) if (fs->parent != NULL) fs_set_verror(fs->parent, fmt, args); else { - str_truncate(fs->last_error, 0); - str_vprintfa(fs->last_error, fmt, args); + char *old_error = fs->last_error; + fs->last_error = i_strdup_vprintf(fmt, args); + /* free after strdup in case args point to the old error */ + i_free(old_error); } } @@ -538,9 +537,9 @@ const char *fs_last_error(struct fs *fs) if (fs->parent != NULL) return fs_last_error(fs->parent); - if (str_len(fs->last_error) == 0) + if (fs->last_error == NULL) return "BUG: Unknown fs error"; - return str_c(fs->last_error); + return fs->last_error; } const char *fs_file_last_error(struct fs_file *file)