Yes, connecting automatically to any available WiFi connections isn't free of danger, it is nothing for hackers to hack your phone, if you don't take precautionary steps.
So it is always advisable to switch off the feature of connecting to nearby WiFi networks automatically whenever you are using your smartphone, laptop or tablet.
The next thing you need to do is keeping a close watch on your wireless network. Today most of the smartphones are having the option of connecting to the wireless networks like a router in the home, office or any wireless hotspot they get on the move. Though going wireless is apparently beneficial for increased speeds and for saving data usage costs, but it is surely a potential security threat. But with proper measures this risks can be cut short.
You need to make it a habit of switch off a wireless connection whenever it's not in use. It will also help you save on the battery power, while ensuring that malicious hackers can't connect to your device without your knowledge. It is also a good practice to thoroughly check your phone's network security settings if that is configured to automatically connect to a network in range.
The next thing which will give you an added layer of security is keeping it password protected.
A common threat that are prevalent with unknown wireless networks and with hotspots is the "evil twin" attack.
This happens when a malicious hacker offers access to a wireless connection that appears to be a legitimate hotspot from a well-known company. Once you connect to this "hotspot", you would get requests for login and password details as well as other information which would be recorded to access the accounts later on. So, one has to refrain from accepting such connectivity and save their data from unnecessary risks.
Finally, people using phones to communicate through a corporate environment should consider using of a VPN (Virtual Private Network) while setting up a secured private network. This will allow the users to access only specific sites and even the company resources while on the move. This will automatically reduce the risk of potentially sensitive data being accessed by unwanted and unknown people.