From: Vsevolod Stakhov Date: Mon, 28 Sep 2009 15:11:05 +0000 (+0400) Subject: * Fix race between learn and classify X-Git-Tag: 0.3.0~169 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=ee3d2182e1ce2a65822ac5a7dc51201a7c8b327d;p=rspamd.git * Fix race between learn and classify --- diff --git a/src/classifiers/winnow.c b/src/classifiers/winnow.c index 6abd973ed..0b156176e 100644 --- a/src/classifiers/winnow.c +++ b/src/classifiers/winnow.c @@ -126,7 +126,11 @@ winnow_classify (struct classifier_ctx *ctx, statfile_pool_t *pool, GTree *input } } - g_tree_foreach (input, classify_callback, &data); + if (data.file != NULL) { + statfile_pool_lock_file (pool, data.file); + g_tree_foreach (input, classify_callback, &data); + statfile_pool_unlock_file (pool, data.file); + } if (data.count != 0) { *res = (data.sum / data.count); diff --git a/src/controller.c b/src/controller.c index 82dc02c0f..c88994b9f 100644 --- a/src/controller.c +++ b/src/controller.c @@ -411,6 +411,9 @@ controller_read_socket (f_str_t *in, void *arg) case STATE_COMMAND: s = fstrcstr (in, session->session_pool); params = g_strsplit (s, " ", -1); + + memory_pool_add_destructor (session->session_pool, (pool_destruct_func)g_strfreev, params); + len = g_strv_length (params); if (len > 0) { cmd = g_strstrip (params[0]); @@ -446,7 +449,6 @@ controller_read_socket (f_str_t *in, void *arg) } } - g_strfreev (params); break; case STATE_LEARN: session->learn_buf = in; diff --git a/src/statfile.c b/src/statfile.c index d1382e368..20b415bf6 100644 --- a/src/statfile.c +++ b/src/statfile.c @@ -171,8 +171,7 @@ statfile_pool_open (statfile_pool_t *pool, char *filename) } - /* XXX: this is temporary copy of name to avoid strdup early */ - new_file->filename = filename; + g_strlcpy (new_file->filename, filename, sizeof (new_file->filename)); new_file->len = st.st_size; if (statfile_pool_check (new_file) == -1) { pool->opened --; @@ -180,7 +179,6 @@ statfile_pool_open (statfile_pool_t *pool, char *filename) } pool->occupied += st.st_size; - new_file->filename = memory_pool_strdup (pool->pool, filename); new_file->open_time = time (NULL); new_file->access_time = new_file->open_time; new_file->lock = memory_pool_get_mutex (pool->pool); @@ -400,7 +398,7 @@ stat_file_t * statfile_pool_is_open (statfile_pool_t *pool, char *filename) { static stat_file_t f, *ret; - f.filename = filename; + g_strlcpy (f.filename, filename, sizeof (f.filename)); ret = bsearch (&f, pool->files, pool->opened, sizeof (stat_file_t), cmpstatfile); return ret; } diff --git a/src/statfile.h b/src/statfile.h index be5d15b71..de2ced1b0 100644 --- a/src/statfile.h +++ b/src/statfile.h @@ -32,7 +32,7 @@ struct stat_file_header { * Section header */ struct stat_file_section { - uint32_t code; /**< section's code */ + uint64_t code; /**< section's code */ uint64_t length; /**< section's length in blocks */ }; @@ -42,8 +42,8 @@ struct stat_file_section { struct stat_file_block { uint32_t hash1; /**< hash1 (also acts as index) */ uint32_t hash2; /**< hash2 */ - float value; /**< float value */ uint32_t last_access; /**< last access to block since create time of file */ + float value; /**< float value */ }; /** @@ -59,7 +59,11 @@ struct stat_file { * Common view of statfile object */ typedef struct stat_file_s { - char *filename; /**< name of file */ +#ifdef HAVE_PATH_MAX + char filename[PATH_MAX]; /**< name of file */ +#else + char filename[MAXPATHLEN]; /**< name of file */ +#endif int fd; /**< descriptor */ void *map; /**< mmaped area */ off_t seek_pos; /**< current seek position */