How did Harry Potter set Dobby free?
Dobby is a house elf, and he could only be freed if his current master presents him with clothes. After Harry Potter destroyed Tom Riddle's (Lord Voldemort) diary, he returned it to Lucius Malfoy who had slipped it into Ginny Weasley's cauldron at Flourish and Blotts. Harry takes off his sock and hides it in the diary. He then gives the diary with the sock in to Malfoy. Malfoy, not knowing about the sock, throws it Dobby. When Dobby catches it he opens it and finds a sock, because Malfoy had given Dobby the sock he was free.