]> source.dussan.org Git - rspamd.git/commitdiff
* Fix race between learn and classify
authorVsevolod Stakhov <vsevolod@rambler-co.ru>
Mon, 28 Sep 2009 15:11:05 +0000 (19:11 +0400)
committerVsevolod Stakhov <vsevolod@rambler-co.ru>
Mon, 28 Sep 2009 15:11:05 +0000 (19:11 +0400)
src/classifiers/winnow.c
src/controller.c
src/statfile.c
src/statfile.h

index 6abd973edd12e0d633a709bf5be15e4a4079f3d1..0b156176e5b2f3f91e14237a034c11bd60d33457 100644 (file)
@@ -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);
index 82dc02c0f9e16789ff2b5a120eb2ac93b1347049..c88994b9f847752c7315abddfcd89e83f28cd088 100644 (file)
@@ -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;
index d1382e368d49aaffeeafd76f78568cf0a7c37080..20b415bf638f9bc8e8912cccb5a16eda377e8cb4 100644 (file)
@@ -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;
 }
index be5d15b71703b5bee8cebf57d3768c955cb4f44c..de2ced1b04f026cac4dc533a7f2603b9f185ca85 100644 (file)
@@ -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                              */