Do not include struct fuse_buf in struct fuse_worker
authorNikolaus Rath <Nikolaus@rath.org>
Mon, 17 Sep 2018 09:45:16 +0000 (10:45 +0100)
committerNikolaus Rath <Nikolaus@rath.org>
Mon, 17 Sep 2018 09:45:16 +0000 (10:45 +0100)
This is only used in fuse_do_work(), so we can put it on
the stack.

lib/fuse_loop_mt.c

index 273943551fc6baedd989a956c08da1d64c032eb2..53e5b9b9be3941b4a3dfdc2a704aa91354a1f7d8 100644 (file)
@@ -32,8 +32,6 @@ struct fuse_worker {
        struct fuse_worker *prev;
        struct fuse_worker *next;
        pthread_t thread_id;
-       size_t bufsize;
-       struct fuse_buf fbuf;
        struct fuse_chan *ch;
        struct fuse_mt *mt;
 };
@@ -115,13 +113,16 @@ static void *fuse_do_work(void *data)
 {
        struct fuse_worker *w = (struct fuse_worker *) data;
        struct fuse_mt *mt = w->mt;
+       struct fuse_buf fbuf;
+
+       memset(&fbuf, 0, sizeof(struct fuse_buf));
 
        while (!fuse_session_exited(mt->se)) {
                int isforget = 0;
                int res;
 
                pthread_setcancelstate(PTHREAD_CANCEL_ENABLE, NULL);
-               res = fuse_session_receive_buf_int(mt->se, &w->fbuf, w->ch);
+               res = fuse_session_receive_buf_int(mt->se, &fbuf, w->ch);
                pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, NULL);
                if (res == -EINTR)
                        continue;
@@ -143,8 +144,8 @@ static void *fuse_do_work(void *data)
                 * This disgusting hack is needed so that zillions of threads
                 * are not created on a burst of FORGET messages
                 */
-               if (!(w->fbuf.flags & FUSE_BUF_IS_FD)) {
-                       struct fuse_in_header *in = w->fbuf.mem;
+               if (!(fbuf.flags & FUSE_BUF_IS_FD)) {
+                       struct fuse_in_header *in = fbuf.mem;
 
                        if (in->opcode == FUSE_FORGET ||
                            in->opcode == FUSE_BATCH_FORGET)
@@ -157,7 +158,7 @@ static void *fuse_do_work(void *data)
                        fuse_loop_start_thread(mt);
                pthread_mutex_unlock(&mt->lock);
 
-               fuse_session_process_buf_int(mt->se, &w->fbuf, w->ch);
+               fuse_session_process_buf_int(mt->se, &fbuf, w->ch);
 
                pthread_mutex_lock(&mt->lock);
                if (!isforget)
@@ -173,7 +174,7 @@ static void *fuse_do_work(void *data)
                        pthread_mutex_unlock(&mt->lock);
 
                        pthread_detach(w->thread_id);
-                       free(w->fbuf.mem);
+                       free(fbuf.mem);
                        fuse_chan_put(w->ch);
                        free(w);
                        return NULL;
@@ -182,6 +183,7 @@ static void *fuse_do_work(void *data)
        }
 
        sem_post(&mt->finish);
+       free(fbuf.mem);
 
        return NULL;
 }
@@ -256,14 +258,12 @@ static struct fuse_chan *fuse_clone_chan(struct fuse_mt *mt)
 static int fuse_loop_start_thread(struct fuse_mt *mt)
 {
        int res;
-
        struct fuse_worker *w = malloc(sizeof(struct fuse_worker));
        if (!w) {
                fprintf(stderr, "fuse: failed to allocate worker structure\n");
                return -1;
        }
        memset(w, 0, sizeof(struct fuse_worker));
-       w->fbuf.mem = NULL;
        w->mt = mt;
 
        w->ch = NULL;
@@ -296,7 +296,6 @@ static void fuse_join_worker(struct fuse_mt *mt, struct fuse_worker *w)
        pthread_mutex_lock(&mt->lock);
        list_del_worker(w);
        pthread_mutex_unlock(&mt->lock);
-       free(w->fbuf.mem);
        fuse_chan_put(w->ch);
        free(w);
 }