[WGID-258847] Add null check after malloc