Fix for possible crash in TryFindBeads

"SBead* beads" is deallocated even if it's a nullptr (i.e. if error
happened before memory allocation or memory allocation failed).