I need to terminate the program using a non-zero status if malloc returns NULL. Using status 3 gives me a segmentation fault. what do I do?
/*
 * Create a new user with the given name.  Insert it at the tail of the list
 * of users whose head is pointed to by *user_ptr_add.
 *
 * Return:
 *   - 0 if successful
 *   - 1 if a user by this name already exists in this list
 *   - 2 if the given name cannot fit in the 'name' array
 *       (don't forget about the null terminator)
 */
int create_user(const char *name, User **user_ptr_add) {
    User *curr1 = *user_ptr_add;

    //check if user with same name exists
    while(curr1 != NULL){
        if (strcmp(curr1->name, name) == 0){
            return 1;
        }
        curr1 = curr1->next;
    }

    // check if the name cannot fit in the 'name' array
    // use -1 to save space for the null terminator
    if (strlen(name) >= MAX_NAME - 1){
        return 2;
    }

    // create a new user and add it to the end of the list
    User *new_user = malloc(sizeof(User));
    if (new_user == NULL){
        perror("Cannot allocate space for user");
        exit(3);
    }

    strcpy(new_user->name, name);
    new_user->next = NULL;

    User *curr2 = *user_ptr_add;
    if (curr2 == NULL) {
        *user_ptr_add = new_user;
    }
    else {
        while (curr2->next != NULL){
            curr2 = curr2->next;
        }
    }

    curr2->next = new_user;
    for (int i = 0; i < MAX_FRIENDS; i++) {  
        new_user->friends[i] = NULL;
    }
    for (int i = 0; i < MAX_FRIENDS; i++) {  
        new_user->profile_pic[i] = '\0';
    } 
    new_user->first_post = NULL;  
    return 0;
}
