Changeset 3459 for trunk/src


Ignore:
Timestamp:
Sep 15, 2020, 11:09:19 AM (5 years ago)
Author:
bird
Message:

kash: more sh_destroy work.

Location:
trunk/src/kash
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/kash/generated/init.c

    r3435 r3459  
    136136extern void hash_special_builtins(struct shinstance *);
    137137
    138 struct redirtab {
    139         struct redirtab *next;
    140         short renamed[10];
    141 };
    142 
    143138
    144139
  • trunk/src/kash/redir.c

    r3449 r3459  
    7575
    7676MKINIT
    77 struct redirtab {
    78         struct redirtab *next;
    79         short renamed[10];
    80 };
    81 
    8277
    8378//MKINIT struct redirtab *redirlist;
  • trunk/src/kash/shinstance.c

    r3458 r3459  
    278278
    279279    sh_int_unlink(psh);
     280
     281    /* shinstance stuff: */
    280282    shfile_uninit(&psh->fdtab, psh->tracefd);
    281283    sh_free_string_vector(psh, &psh->shenviron);
    282 
     284    sh_free(psh, psh->children);
     285    psh->children = NULL;
    283286#ifndef SH_FORKED_MODE
    284287    /** @todo children. */
     
    323326    psh->cmdenviron = NULL;
    324327
    325 #if 0
    326328    /* expand.c */
    327     char               *expdest;        /**< output of current string */
    328     struct nodelist    *argbackq;       /**< list of back quote expressions */
    329     struct ifsregion    ifsfirst;       /**< first struct in list of ifs regions */
    330     struct ifsregion   *ifslastp;       /**< last struct in list */
    331     struct arglist      exparg;         /**< holds expanded arg list */
    332     char               *expdir;         /**< Used by expandmeta. */
    333 #endif
     329    if (psh->ifsfirst.next)
     330    {
     331        struct ifsregion *ifsrgn = psh->ifsfirst.next;
     332        psh->ifsfirst.next = NULL;
     333        do
     334        {
     335            struct ifsregion *next = ifsrgn->next;
     336            sh_free(psh, ifsrgn);
     337            ifsrgn = next;
     338        } while (ifsrgn);
     339    }
     340    psh->ifslastp = NULL;
     341    sh_free(psh, psh->expdir);
     342    psh->expdir = NULL;
    334343
    335344    /* exec.h/exec.c */
     
    392401    time_t              mailtime[MAXMBOXES]; /**< times of mailboxes */
    393402
    394     /* main.h */
    395     shpid               rootpid;        /**< pid of main shell. */
    396     int                 rootshell;      /**< true if we aren't a child of the main shell. */
    397     struct shinstance  *psh_rootshell;  /**< The root shell pointer. (!rootshell) */
    398 
    399     /* memalloc.h */
    400     char               *stacknxt/* = stackbase.space*/;
    401     int                 stacknleft/* = MINSIZE*/;
    402     int                 sstrnleft;
    403     int                 herefd/* = -1 */;
    404 
    405403    /* myhistedit.h */
    406     int                 displayhist;
    407404#ifndef SMALL
    408405    History            *hist;
    409406    EditLine           *el;
    410407#endif
     408#endif
    411409
    412410    /* output.h */
    413     struct output       output;
    414     struct output       errout;
    415     struct output       memout;
    416     struct output      *out1;
    417     struct output      *out2;
    418 
    419     /* output.c */
    420 #define OUTBUFSIZ BUFSIZ
    421 #define MEM_OUT -3                      /**< output to dynamically allocated memory */
     411        if (psh->output.buf != NULL)
     412    {
     413        ckfree(psh, psh->output.buf);
     414        psh->output.buf = NULL;
     415        }
     416        if (psh->errout.buf != NULL)
     417    {
     418        ckfree(psh, psh->errout.buf);
     419        psh->errout.buf = NULL;
     420        }
     421        if (psh->memout.buf != NULL)
     422    {
     423        ckfree(psh, psh->memout.buf);
     424        psh->memout.buf = NULL;
     425        }
    422426
    423427    /* options.h */
    424     struct optent       optlist[NOPTS];
    425     char               *minusc;         /**< argument to -c option */
    426     char               *arg0;           /**< $0 */
    427     struct shparam      shellparam;     /**< $@ */
    428     char              **argptr;         /**< argument list for builtin commands */
    429     char               *optionarg;      /**< set by nextopt */
    430     char               *optptr;         /**< used by nextopt */
    431     char              **orgargv;        /**< The original argument vector (for cleanup). */
    432     int                 arg0malloc;     /**< Indicates whether arg0 was allocated or is part of orgargv. */
    433 
     428    if (psh->arg0malloc)
     429    {
     430        sh_free(psh, psh->arg0);
     431        psh->arg0 = NULL;
     432    }
     433    if (psh->shellparam.malloc)
     434        sh_free_string_vector(psh, &psh->shellparam.p);
     435    sh_free_string_vector(psh, &psh->orgargv);
     436    psh->argptr = NULL;
     437    psh->minusc = NULL;
     438
     439#if 0
    434440    /* parse.h */
    435441    int                 tokpushback;
     
    450456    int                 quoteflag;      /**< set if (part of) last token was quoted */
    451457    int                 startlinno;     /**< line # where last token started */
     458#endif
    452459
    453460    /* redir.c */
    454     struct redirtab    *redirlist;
    455     int                 fd0_redirected/* = 0*/;
    456 #endif
     461    if (psh->redirlist)
     462    {
     463        struct redirtab *redir = psh->redirlist;
     464        psh->redirlist = NULL;
     465        do
     466        {
     467            struct redirtab *next = redir->next;
     468            sh_free(psh, redir);
     469            redir = next;
     470        } while (redir);
     471    }
    457472    psh->expfnames = NULL; /* stack alloc */
    458473
    459 #if 0
    460     /* show.c */
    461     char                tracebuf[1024];
    462     size_t              tracepos;
    463     int                 tracefd;
    464 
    465     /* trap.h */
    466     int                 pendingsigs;    /**< indicates some signal received */
    467 
    468474    /* trap.c */
    469     char                gotsig[NSIG];   /**< indicates specified signal received */
    470     char               *trap[NSIG+1];   /**< trap handler commands */
    471     char                sigmode[NSIG];  /**< current value of signal */
     475    for (i = 0; i < K_ELEMENTS(psh->trap); i++)
     476        if (!psh->trap[i])
     477        { /* likely */ }
     478        else
     479        {
     480            sh_free(psh, psh->trap[i]);
     481            psh->trap[i] = NULL;
     482        }
    472483
    473484    /* var.h */
    474     struct localvar    *localvars;
    475     struct var          vatty;
    476     struct var          vifs;
    477     struct var          vmail;
    478     struct var          vmpath;
    479     struct var          vpath;
    480 #ifdef _MSC_VER
    481     struct var          vpath2;
    482 #endif
    483     struct var          vps1;
    484     struct var          vps2;
    485     struct var          vps4;
    486 #ifndef SMALL
    487     struct var          vterm;
    488     struct var          vhistsize;
    489 #endif
    490     struct var          voptind;
    491 #ifdef PC_OS2_LIBPATHS
    492     struct var          libpath_vars[4];
    493 #endif
    494 #ifdef SMALL
    495 # define VTABSIZE 39
    496 #else
    497 # define VTABSIZE 517
    498 #endif
    499     struct var         *vartab[VTABSIZE];
    500 
    501     /* builtins.h */
    502 
    503     /* bltin/test.c */
    504     char              **t_wp;
    505     struct t_op const  *t_wp_op;
    506 #endif
     485    if (psh->localvars)
     486    {
     487        struct localvar *lvar = psh->localvars;
     488        psh->localvars = NULL;
     489        do
     490        {
     491            struct localvar *next = lvar->next;
     492                        if (!(lvar->flags & VTEXTFIXED))
     493                sh_free(psh, lvar->text);
     494            sh_free(psh, lvar);
     495            lvar = next;
     496        } while (lvar);
     497    }
     498
     499    for (i = 0; i < K_ELEMENTS(psh->vartab); i++)
     500    {
     501        struct var *var = psh->vartab[i];
     502        if (!var)
     503        { /* likely */ }
     504        else
     505        {
     506            psh->vartab[i] = NULL;
     507            do
     508            {
     509                struct var *next = var->next;
     510                if (!(var->flags & VTEXTFIXED))
     511                    sh_free(psh, var->text);
     512                if (!(var->flags & VSTRFIXED))
     513                    sh_free(psh, var);
     514                var = next;
     515            } while (var);
     516        }
     517    }
    507518
    508519    /*
  • trunk/src/kash/shinstance.h

    r3457 r3459  
    169169};
    170170
    171 /* redir.c / bird */
     171/* redir.c */
     172struct redirtab {
     173        struct redirtab *next;
     174        short renamed[10];
     175};
     176
    172177/**
    173178 * This is a replacement for temporary node field nfile.expfname.
     
    245250
    246251    /* expand.c */
    247     char               *expdest;        /**< output of current string */
     252    char               *expdest;        /**< output of current string (stack) */
    248253    struct nodelist    *argbackq;       /**< list of back quote expressions */
    249254    struct ifsregion    ifsfirst;       /**< first struct in list of ifs regions */
    250255    struct ifsregion   *ifslastp;       /**< last struct in list */
    251     struct arglist      exparg;         /**< holds expanded arg list */
     256    struct arglist      exparg;         /**< holds expanded arg list (stack) */
    252257    char               *expdir;         /**< Used by expandmeta. */
    253258
Note: See TracChangeset for help on using the changeset viewer.