Read from the open file fp, and create the linked data structure that creates a Dependency node, Rule node and Action node for each dependency, rule and action.

The code is currently giving me a no stack, malloc error when I try to run it in gdb, how do I fix that?

Rule *parse_file(FILE *fp) {
    // Implement this function and remove the stubbed return statement below.
    Rule *head = malloc(sizeof(Rule));
    if (head == NULL){
        perror("malloc");
        exit(1);
    }

    char line[MAXLINE];
   while(fgets(line, MAXLINE, fp) != NULL){

   // checking if the first character is a tab to determine whether it is a target line or an action line
    if (strchr(line, "\t") != line){
        if (is_comment_or_empty(line) == 0){
            head->target = strtok(line, " : ");
            Rule *prev_rule = head;
            Dependency *prev_dep;

            char *token;
            token = strtok(line, " ");
            while (token != NULL){
                Dependency *dep = malloc(sizeof(Dependency));
                if (dep == NULL){
                    perror("malloc");
                    exit(1);
                }
                Rule *rule = malloc(sizeof(Rule));
                if (rule == NULL){
                    perror("malloc");
                    exit(1);
                }
                prev_rule->dependencies = dep;
                prev_rule->next_rule = rule;
                rule->target = token;
                dep->rule = rule;

                // change prev_rule and prev_dep to current dep and rule
                prev_rule = rule;
                prev_dep = dep;

                token = strtok(line, " ");
            }
         }
     } else { // the first character is a tab
         if (is_comment_or_empty(line) == 0){
             if((strstr(line, "-o") != NULL) || (strstr(line, "-c") != NULL)){
                   strtok(line, " ");
                   Action *action = malloc(sizeof(Action));
                   char *argument = strtok(line, " ");
                   action->args = &argument;
             }
         }
     }
  }

        return NULL;
}
             

typedef struct action_node {
    char **args;  // An array of strings suitable to be passed to execvp
    struct action_node *next_act;
} Action;

typedef struct dep_node {
    struct rule_node *rule;
    struct dep_node *next_dep;
} Dependency;

typedef struct rule_node {
    char *target;
    Dependency *dependencies;
    Action *actions;
    struct rule_node *next_rule;
} Rule;

