bugfix : the object needs to be released only if it has been found

otherwise we are trying to release a null pointer