Could Madrid prevent the exit of the EU by Gibraltar under Brexit?
It seems unlikely, but a line in the European Council's draft Brexit negotiating guidelines reads:
After the United Kingdom leaves the Union, no agreement between the EU and the United Kingdom may apply to the territory of Gibraltar without the agreement between the Kingdom of Spain and the United Kingdom.
Reports that Spain could actually veto Brexit for Gibraltar seem unfounded, however, since the above statement clearly applies to the time after the UK has left the EU.
Voters in Gibraltar voted overwhelmingly to remain inside the EU. There is overwhelming support there for its continued status as a British Overseas Territory.