Trapping and detrapping of hydrogen in carbon-based materials exposed to hydrogen gas