I just purchased a used Hyundai Elantra gls with 64,000 miles and on the way home, it stalled in my driveway as I waited for my garage door to open. I restarted it and put the car into Park. The car raced on its own and then came down. Very erratic idling.
That sounds a lot like a vacuum leak. Are you saying it didn’t do this at all when you looked at the car?
When I looked at the car before buying it, I drove it on the highway for about 10 miles and in the city for about 6 miles round trip. It never stalled and seemed fine.