After feeding a horse some sugar and put it back in the stables, when closing the door afterwards, you will receive the sugar again.
Test:
Standing on the ground, give a horse some sugar, then close a door afterwards. (the horse is not in a leash)