why is this giving me segmentation fault?
if (curr->dependencies == NULL) {
    dep = malloc(sizeof(Dependency));

    if (strcmp(curr->target, token) != 0) {
        r = malloc(sizeof(Rule));
        r->target = strdup(token);
        r->dependencies = NULL;
        r->actions = NULL;
        r->next_rule = NULL;
        dep->next_dep = NULL;
        dep->rule = r;
        printf("%s\n", dep->rule->target);
        curr->dependencies = dep;
    }

} else {
    while (curr->dependencies != NULL) {
        curr->dependencies = curr->dependencies->next_dep;
    }

    r = malloc(sizeof(Rule));
    r->target = strdup(token);
    r->actions = NULL;
    r->next_rule = NULL;
    dep->next_dep = NULL;
    dep->rule = r;
    curr->dependencies = dep;
    printf("%s\n", curr->dependencies->next_dep->rule->target);
}
}