Dobby (28 June (year unknown) – March, 1998) was a male house-elf who served the Malfoy family. His masters were Dark Wizards who treated him cruelly. In 1992, he tried to warn Harry Potter of the plot to have the Chamber of Secrets reopened which he came to know via the contact between his masters and Lord Voldemort. Dobby kept hurting himself in numerous ways, e.g. ironing his hands, hitting his head against a lamp, and banging his head against cabinets. He felt this was necessary because he was disobeying his masters, the Malfoy family. At the end of that school year, after Harry had vanquished the memory of Tom Riddle and the basilisk in the Chamber of Secrets, he tricked Lucius Malfoy into freeing Dobby by placing his own sock inside The Diary of Tom Riddle. Lucius disgustedly ripped the sock off the book and threw the sock into the air, where Dobby caught it.

More Info: harrypotter.wikia.com