To prevent the custard filling from leaking out of the donuts, make sure the donuts are completely cooled before filling them. Use a piping bag to carefully inject the custard into the donuts, avoiding overfilling.