Use atexit to ensure proper shutdown. - sam - An updated version of the sam text editor.
 (HTM) git clone git://vernunftzentrum.de/sam.git
 (DIR) Log
 (DIR) Files
 (DIR) Refs
 (DIR) LICENSE
       ---
 (DIR) commit 1d7381514a5589c78eca12a92b341fbd0de9ff2f
 (DIR) parent 3a8f45f007849613466d20ed16760917bdb2bf9d
 (HTM) Author: Rob King <jking@deadpixi.com>
       Date:   Thu, 20 Oct 2016 16:04:18 -0500
       
       Use atexit to ensure proper shutdown.
       
       Diffstat:
         sam/file.c                          |       4 +---
         sam/mesg.c                          |       1 -
         sam/sam.c                           |       3 ++-
         sam/sam.h                           |       1 +
       
       4 files changed, 4 insertions(+), 5 deletions(-)
       ---
 (DIR) diff --git a/sam/file.c b/sam/file.c
       @@ -20,7 +20,7 @@ enum{
            MAXCACHE=STRSIZE    /* max length of cache. must be < 32K-BLOCKSIZE */
        };
        
       -static void
       +void
        freebufs(void)
        {
            Bterm(undobuf);
       @@ -34,8 +34,6 @@ Fstart(void)
            undobuf = Bopen();
            snarfbuf = Bopen();
            plan9buf = Bopen();
       -
       -    atexit(freebufs);
        }
        
        void
 (DIR) diff --git a/sam/mesg.c b/sam/mesg.c
       @@ -491,7 +491,6 @@ inmesg(Tmesg type)
                break;
        
            case Texit:
       -        shutdown();
                exit(EXIT_SUCCESS);
            }
            return true;
 (DIR) diff --git a/sam/sam.c b/sam/sam.c
       @@ -135,12 +135,12 @@ main(int argc, char *argv[])
            if(file.nused)
                current(file.filepptr[0]);
        
       +    atexit(shutdown);
            setjmp(mainloop);
            cmdloop();
        
            trytoquit();    /* if we already q'ed, quitok will be true */
        
       -    shutdown();
            exit(EXIT_SUCCESS);
        }
        
       @@ -172,6 +172,7 @@ shutdown(void)
                free(tempfile.listptr);
        
            freecmdlists();
       +    freebufs();
        }
        
        void
 (DIR) diff --git a/sam/sam.h b/sam/sam.h
       @@ -207,6 +207,7 @@ void    error_s(Err, char*);
        int execute(File*, Posn, Posn);
        int filematch(File*, String*);
        void    filename(File*);
       +void    freebufs(void);
        void    freecmd(void);
        void    freecmdlists(void);
        File    *getfile(String*);