分函数访问全局指针出现问题

创建的全局变量指针,用分函数访问时发生位置冲突,请问这是为什么

#define _CRT_SECURE_NO_WARNINGS

#include "stdio.h"
#include "stdlib.h"

struct bustype
{
    int ntype;
    int   bus_no;
    int   occurtime;
    struct bustype *next;
    struct bustype *prior;
}*s, *top, *base, *l, *head, *tail;

typedef struct _excel
{
    int bus_no;
    int arrivetime;
    int leavetime;
    char placetype;
    _excel *next;
    //_excel *prior;
}_excel;

struct _flag
{
    int num_s;
    int num_l;
    int num_excel;

}flag;

_excel *excel, *event;

int createstack()
{
    
    s = (struct bustype *)malloc(sizeof(bustype *));
    l = (struct bustype *)malloc(sizeof(bustype *));
    event = (_excel *)malloc(sizeof(_excel *));
    s = top = base;
    l = head = tail;
    struct bustype s_tem[7];
    flag.num_s = 0;
    flag.num_l = 0;
    flag.num_excel = 0;
    s->prior = NULL;
    l->prior = NULL;
    excel->next = event;
    return 0;
}

int check(int bus__no,char placetype,struct bustype *pre)
{
    struct bustype *p;//临时节点
    int i;
    p = base;
    switch (placetype)
    {
    case 's':
    {
        if (s->ntype == 1)
        {
            s->next = (struct bustype *)malloc(sizeof(bustype *));
            s->next->prior = s;
            s = s->next;
            top = s;
            flag.num_s++;
        }
        else
        {
            for (i = 1; i < flag.num_s;i++)
            {
                if (p->bus_no == bus__no)
                {
                    if (p->prior == NULL)
                    {
                        p = p->next;
                        free(p->prior);
                    }
                    else
                    {
                        p->prior->next = p->next;
                        p->next->prior = p->prior;
                        p = p->next;
                        free(p->prior->next);
                        p->prior->next = p;
                    }
                    flag.num_excel++;
                    flag.num_s--;
                    event->bus_no = bus__no;
                    event->arrivetime = s->occurtime;
                    event->leavetime = pre->occurtime;
                    event->placetype = '普';
                    /*excel->arrivetime=event->arrivetime;
                    excel->bus_no = event->bus_no;
                    excel->leavetime = event->leavetime;
                    excel->placetype = event->placetype;*/
                    event = event->next;
                    event = (_excel *)malloc(sizeof(_excel *));

                    
                }
            }
        }
        break;
    }
    case 'l':
    {
        if (l->ntype == 1)
        {
            p = tail;
            l = l->next;
            l = (struct bustype *)malloc(sizeof(bustype *));
            tail = l;
            flag.num_l++;
        }
        else
        {
            for (i = 1; i < flag.num_l; i++)
            {
                if (p->bus_no == bus__no)
                {
                    if (p->prior == NULL)
                    {
                        p = p->next;
                        free(p->prior);
                    }
                    else
                    {
                        p->prior->next = p->next;
                        p->next->prior = p->prior;
                        p = p->next;
                        free(p->prior->next);
                        p->prior->next = p;
                    }
                    flag.num_excel++;
                    flag.num_l--;
                    event->bus_no = bus__no;
                    event->arrivetime = l->occurtime;
                    event->leavetime = pre->occurtime;
                    event->placetype = '便道';
                    event = event->next;
                    event = (_excel *)malloc(sizeof(_excel *));


                }
            }
        }
        break;
    }
    }
    return 0;
}

int input()
{
    do{
        if (flag.num_s < 7)
        {
            scanf("{%d,%d,%d}", s->ntype, s->bus_no, s->occurtime);
            check(s->bus_no, 's', s);//判断
        }
        else
        {
            scanf("{%d,%d,%d}", l->ntype, l->bus_no, l->occurtime);
            check(l->bus_no, 'l', l);
        }
    } while (s->ntype == 6 || l->ntype == 6);
    return 0;
}

int main()
{
    createstack();
    input();
}

img

分函数是什么意思?这错误应该是访问了不该访问的内存导致