Fix for coverity (don't leak memory if the object doesn't exist)