why is this printing garbage sometimes on ssh?
char *list_users(const User *curr) {
    int size = 0;

    const User *curr2 = (User *)curr;
    while (curr2->next != NULL) {
        size += strlen(curr2->name) + 2;
        curr2 = curr2->next;
    }
    size += strlen(curr2->name);

    char *buffer = malloc(sizeof(char) * (size + 1));
    if (buffer == NULL) {
        free(buffer);
        exit(1);
    }

    User *curr3 = (User *)curr;
    while (curr3->next != NULL) {
        strcat(buffer, curr3->name);
        strcat(buffer, "\r\n");
        curr3 = curr3->next;
    }

    strcat(buffer, curr3->name);

    strcat(buffer, "\0");
    strcat(buffer, "\r\n");
    printf("%s", buffer);

    return buffer;
}
