Do we pay the closing only on selling? What if I cancel the listing?

Do we pay the closing only on selling? If we decide to cancel before the term of the listing do we owe anything to the agent?

The Closing commission is to be paid to the Listing Agent only when the property sells. If you decide to cancel your listing before the end of the agreed term, you don't owe anything to the agent.
Even if the property fails to sell during the term of the agreement, you are not required to pay anything to the Listing Agent.

In conclusion, you will need to pay the closing costs only after your property has been sold.

Notes
NOTE: You cannot cancel a listing if the property is under contract — that is, once you’ve accepted an offer.