sapB: fixed memory access problems found by ASAN