Changeset 2372 for neercs


Ignore:
Timestamp:
Jun 13, 2008, 5:01:41 PM (12 years ago)
Author:
Jean-Yves Lamoureux
Message:
  • Added a glazillon of checks for mallocs and frees and stuff (et raph_ael a de bien belles pipes)
File:
1 edited

Legend:

Unmodified
Added
Removed
  • neercs/trunk/src/main.c

    r2371 r2372  
    9191    /* Create screen list */
    9292    screen_list = (struct screen_list*)     malloc(sizeof(struct screen_list));
     93    if(!screen_list)
     94    {
     95        fprintf(stderr, "Can't allocate memory at %s:%d\n", __FUNCTION__, __LINE__);
     96        return -1;
     97    }
    9398    screen_list->screen = (struct screen**) malloc(sizeof(sizeof(struct screen*)));
     99    if(!screen_list->screen)
     100    {
     101        fprintf(stderr, "Can't allocate memory at %s:%d\n", __FUNCTION__, __LINE__);
     102        return -1;
     103    }
    94104    screen_list->count = 0;
    95105    screen_list->width  = cucul_get_canvas_width(cv);
     
    190200                }
    191201            }
     202
     203        if(!screen_list->count) break;
    192204
    193205        for(i = 0; i < screen_list->count; i++) if(screen_list->screen[i]->total)
     
    334346                       screen_list->screen[pty]->y,
    335347                       screen_list->screen[pty]->cv, NULL);
     348
    336349            if(screen_list->screen[pty]->bell)
    337350            {
     
    412425        putenv("TERM=xterm");
    413426        argv = malloc(2 * sizeof(char *));
     427        if(!argv)
     428        {
     429            fprintf(stderr, "Can't allocate memory at %s:%d\n", __FUNCTION__, __LINE__);
     430            return -1;
     431        }
    414432        argv[0] = cmd;
    415433        argv[1] = NULL;
     
    457475    s->w = w+1;
    458476    s->h = h+1;
     477    s->bell = 0;
     478
    459479    s->fd = create_pty(command, w, h, &s->pid);
    460     s->bell = 0;
    461480
    462481    if(s->fd < 0)
     
    471490int destroy_screen(struct screen *s)
    472491{
    473     free(s->buf);
    474     cucul_free_canvas(s->cv);
    475     free(s);
     492    if(s->fd>0)
     493        close(s->fd);
     494    if(s->buf)
     495        free(s->buf);
     496    s->buf = NULL;
     497    if(s->cv)
     498        cucul_free_canvas(s->cv);
     499    s->cv = NULL;
     500    if(s)
     501        free(s);
     502    s = NULL;
    476503    return 1;
    477504}
     
    503530        /* FIXME */
    504531        close(list->screen[n]->fd);
     532        list->screen[n]->fd = -1;
    505533        kill(list->screen[n]->pid, SIGINT);
    506534        ret = waitpid(list->screen[n]->pid, &status, WNOHANG|WUNTRACED|WCONTINUED);
Note: See TracChangeset for help on using the changeset viewer.