why is this giving segmentation fault?
}
else if (strcmp(cmd_argv[0], "post") == 0 && cmd_argc >= 3) {
    printf("first stop!\n");

    int space_needed = 1;
    for (int i = 2; i < cmd_argc; i++) {
        space_needed += strlen(cmd_argv[i]) + 1;
    }

    printf("before space!\n");
    char *contents = malloc(space_needed);
    if (contents == NULL) {
        perror("malloc");
        exit(1);
    }

    printf("after malloc!\n");
    strcpy(contents, cmd_argv[3]);
    for (int i = 2; i < cmd_argc; i++) {
        strcat(contents, " ");
        strcat(contents, cmd_argv[i]);
    }
