current_user_can() causing critical error

The problem is that wp_get_current_user (which current_user_can relies upon) is pluggable, which means it isn’t loaded until after plugins are loaded (to give plugins a chance to override it). That means it’s not available to call from the top level of a plugin file.

Instead, I’d make the role check inside the hook e.g.

function add_media_link_to_admin_menu( $wp_admin_bar ) {
    if ( current_user_can( 'upload_files' ) ) {
        // add Media Library to admin menu
        $wp_admin_bar->add_menu(array(
            'parent' => 'appearance',
            'id' => 'media-library',
            'title' => 'Media Library',
            'href' => '/wp-admin/upload.php',
        ));
    }
}
add_action( 'admin_bar_menu', 'add_media_link_to_admin_menu', 999 );

(However themes are loaded after pluggable functions, so your original code would work fine in a theme.)