t9pfuse: fix memory leak, avoid memory explosion - plan9port - [fork] Plan 9 from user space
 (HTM) git clone git://src.adamsgaard.dk/plan9port
 (DIR) Log
 (DIR) Files
 (DIR) Refs
 (DIR) README
 (DIR) LICENSE
       ---
 (DIR) commit d4ccb0a943fb312d949726827d4e4e71e6a7a0bb
 (DIR) parent ba3110263311be872f4d1d1e11735d7afee1f61a
 (HTM) Author: Ties Bos <gitbisector@gmail.com>
       Date:   Mon, 10 Sep 2012 22:07:26 -0400
       
       9pfuse: fix memory leak, avoid memory explosion
       
       Change is to handle FUSE_FORGET in main loop instead of separate thread for each as 10s of thousands can come in at once.
       Fixes issue 104.
       
       R=0intro, rsc
       http://codereview.appspot.com/6498081
       
       Diffstat:
         M CONTRIBUTORS                        |       1 +
         M src/cmd/9pfuse/main.c               |      13 +++++++++++--
       
       2 files changed, 12 insertions(+), 2 deletions(-)
       ---
 (DIR) diff --git a/CONTRIBUTORS b/CONTRIBUTORS
       t@@ -35,6 +35,7 @@ Rob Kroeger <robkroeger@gmail.com>
        Rob Pike <robpike@gmail.com>
        Russ Cox <rsc@swtch.com>
        Sean McKean <smckean83@gmail.com>
       +Ties Bos <gitbisector@gmail.com>
        Tim Newsham <tim.newsham@gmail.com>
        Tony Lainson <t.lainson@gmail.com>
        Venkatesh Srinivas <extrudedaluminiu@gmail.com>
 (DIR) diff --git a/src/cmd/9pfuse/main.c b/src/cmd/9pfuse/main.c
       t@@ -257,6 +257,7 @@ allocfh(CFid *fid)
        {
                return _alloc(fid, 0);
        }
       +
        uvlong
        allocnodeid(CFid *fid)
        {
       t@@ -412,6 +413,7 @@ fuseforget(FuseMsg *m)
                        fprint(2, "bad count in forget\n");
                ff->ref = 1;
                freefusefid(ff);
       +        freefusemsg(m);
        }
        
        /*
       t@@ -1255,8 +1257,15 @@ fusedispatch(void *v)
                        fusehandlers[fuselist[i].op] = fuselist[i].fn;
                }
        
       -        while((m = recvp(fusechan)) != nil)
       -                threadcreate(fusethread, m, STACK);
       +        while((m = recvp(fusechan)) != nil) {
       +                switch(m->hdr->opcode) {
       +                case FUSE_FORGET:
       +                         fusehandlers[m->hdr->opcode](m);
       +                        break;
       +                default: 
       +                        threadcreate(fusethread, m, STACK);
       +                }
       +        }
        }
        
        void*