On what airline is your connecting flight? And where is your final destination?
Budapest isn't a huge airport, but a 40 minute connection is really tight. I probably wouldn't risk it, and I'd book a later flight.
Note that if you are connecting on another carrier, the second airline doesn't have an obligation to reaccomodate you on a later flight should your Malev flight arrive late.