typedef struct user {
    char name[MAX_NAME];
    char profile_pic[MAX_NAME];  // This is a *filename*, not the file contents.
    struct post *first_post;
    struct user *friends[MAX_FRIENDS];
    struct user *next;
} User;

int delete_user(const char *name, User **user_ptr_del) {
    if (find_user(name, *user_ptr_del) == NULL) {
        return 1;
    }

    // at the point, confirmed that the user exists
    User *user_del = find_user(name, *user_ptr_del);
    // Post *user_posts = user_del->first_post;

    // only loop if there are posts
    if (user_del->first_post != NULL) {
        // user_del has posts, can loop and free now
        Post *user_posts = user_del->first_post;
        while (user_posts->next != NULL) {
            // need to store copy of rest of list
            // or else unable to access after freeing
            Post *temp = user_posts->next;
            free(user_posts->date);
            free(user_posts->contents);
            free(user_posts);
            user_del->first_post = temp; // off!!
        }
how to fix segmentation error