cpp: fixing reference counting problem in test