How does this code fail to work as explained in the doc below:

/*
 * Make a new post from 'author' to the 'target' user,
 * containing the given contents, IF the users are friends.
 *
 * Insert the new post at the *front* of the user's list of posts.
 *
 * 'contents' is a pointer to heap-allocated memory - you do not need
 * to allocate more memory to store the contents of the post.
 *
 * Return:
 *   - 0 on success
 *   - 1 if users exist but are not friends
 *   - 2 if either User pointer is NULL
 */
int make_post(const User *author, User *target, char *contents) {
    if(author == NULL || target == NULL){
        return 2;
        free(contents);
        }

    int i =0;
    while((author->friends)[i] != NULL && i != MAX_FRIENDS){
        if((author->friends)[i] == target){
            Post *p = malloc(sizeof(Post));
            strcpy(p->author, author->name);
            p->contents = contents;
            p->date = malloc(sizeof(time_t));
            time(p->date); 
            p->next = target->first_post;

            target->first_post = p;
            return 0;
        }
        i++;
    }
    free(contents);
    return 1;
}