Only close curl connection if it is non-null