If a house elf’s master dies and the master has no descendants of any kind, would the house elf be freed?
The house-elf's fate is determined by the will of the deceased.
That said, usually a house-elf would stay in the household it was serving already. House-elves are servants of families, not individuals.
"The wizard family Dobby serves, sir...Dobby is a house-elf - bound to serve one house and one family for ever..."
(Chamber of Secrets, Chapter 2, Dobby's Warning).
It was normal for house-elves to remain within one particular household for their entire lives, as is evident from the generations of house-elves displayed on the walls in Grimmauld Place.
We only have one known instance of a house-elf moving to serve a new master or household as a result of a death - Kreacher. This example is a complex one because the rules governing Kreacher's succession were intertwined with the succession of Grimmauld Place and the particular requirements of the Black family in relation to this. Namely, only male Blacks can acquire the Black inheritance in order of succession.
"Black family tradition decreed that the house was handed down the direct line, to the next male with the name of Black. Sirius was the very last of the line as his younger brother, Regulus, predeceased him and both were childless."
(Half-Blood Prince, Chapter 3, Will and Won't).
These strict preconditions were not necessarily typical of other wizarding families. The Blacks are known to be rather old-fashioned and aristocratic, after all. What is significant is that when the last remaining member of the family who was eligible to own Kreacher died the matter of succession was determined by the will of the deceased. Sirius determines that Harry will inherit everything he owns (including his house-elf).
"But first of all I must tell you that Sirius's will was discovered a week ago and that he left you everything he owned."
(Half-Blood Prince, Chapter 3, Will and Won't).
And, despite suspected complications involving Black family curses, this is exactly what happens.
"Well, that simplifies matters," said Dumbledore cheerfully. "It seems that Sirius knew what he was doing. You are the rightful owner of number twelve, Grimmauld Place, and of Kreacher."
(Half-Blood Prince, Chapter 3, Will and Won't).
It seems clear that when the last member of a wizarding family dies that they have the right to determine who their house-elf passes on to. This is established through their will. House-elves are treated as slaves who are the rightful property of witches and wizards so it's no great surprise that they are divvied up in the same way as furniture and personal items, according to the will of the deceased. If a wizard doesn't leave a will or they don't specify a designated person to inherit the elf then it's likely that the Office for House-Elf Relocation mentioned in Bellatrix's answer kicks into force in order to find a new home for the elf.
So, no, the elf isn't set free. Remember that the vast majority of elves view freedom as a mark of deepest shame. House-elves are usually free only when they have been released by their masters - and this event is very rare and profoundly humiliating for the elf. Freedom is seen as a sign that the house-elf has failed the family. When a house-elf's master dies they would be desperate to be allocated a new master. They would certainly not crave freedom. Knowing this, and knowing the value of a dutiful house-elf, wizarding society would be sure to create a system of house-elf ownership where elves are passed onto new owners without delay. Giving the elf to the person named in the will would seem to ensure this.
I believe the answer to this question relies on whether you view the house-elves as bound to the house, or the family. This is actually an open question, as far as I can tell. There was a hint at the answer in the old WOMBAT test on JKR's website as discussed in this question, but it's inconclusive.
If the house-elf's allegiance is to the house:
My assumption would be that in this case, the elf would go to whoever owns that house (perhaps the Ministry, as suggested in a comment above, until a "proper" owner is found - say, if the house is purchased).
This idea is supported by the following book quotes:
“Yeah, Mum’s always wishing we had a house-elf to do the ironing,” said George. “But all we’ve got is a lousy old ghoul in the attic and gnomes all over the garden. House-elves come with big old manors and castles and places like that; you wouldn’t catch one in our house…” - Chamber of Secrets
This kind of implies that if you came into some money, and bought yourself an old estate with a manor, you might also get the house's house-elf's allegiance. This would also imply that if you moved away from your historic estate, the house-elf wouldn't go with you, which does seem surprising compared to the loyalty and servitude they show in the rest of the series. However, George's comment could also be interpreted as meaning that the types of families likely to own these houses are also likely to have house-elves, which is a slightly different scenario.
"You see," Dumbledore said, turning back to Harry and again speaking as though Uncle Vernon had not uttered, "if you have indeed inherited the house, you have also inherited —" He flicked his wand for a fifth time. There was a loud crack, and a house- elf appeared. - Half Blood Prince
This one seems like a pretty clear if-then statement. If Harry has the house, he also has the house-elf. Arguably, this could be intended as "if you have indeed inherited everything that Sirius owned, you have also inherited Kreacher" - but overall, I think the implication is that the house-elf is tied to the house.
One further idea supporting this is that Hogwarts also has house-elves, and is not a family-owned building. Instead, the house-elves appear to take the school's current Headmaster or Headmistress as their master, as noted in the answers to this question.
This scenario raises the further question of, "If a house-elf's allegiance is to a house and not a family, what happens if a house is destroyed?" Would their allegiance switch to the plot of land? What if it's never rebuilt upon?
If the house-elf's allegiance is to the family:
Then I suppose they would be free. Perhaps they would be able to choose another family, or alternatively would be able to work somewhere like Hogwarts, which is an institution rather than a family.
I don't have any specific quotes supporting this view, which indicates to me that the above scenario is the most likely one; however, given how their servitude is portrayed in the books (and the loyalty that elves like Kreacher and Winky display to their masters) it does seem more intuitive that they would choose to stick with the person or family over the physical building. However, the quotes appear to disagree with this view.
They may be ‘jobless’, there’s an Office for House-Elf Relocation.
Though it’s unclear exactly what happens to a house-elf when their owner dies leaving no heir, there’s an Office for House-Elf Relocation at the Ministry, so presumably house-elves sometimes need relocating. Though some of these may be intentionally freed, others’ owners may have died.
“After two years at the Office for House-Elf Relocation, years he describes as “tedious in the extreme,” he was transferred to the Beast Division, where his prodigious knowledge of bizarre magical animals ensured his rapid promotion.”
- Fantastic Beasts and Where to Find Them
As they’ve loyally served until their owners’ death, presumably it’s easier for a house-elf whose owner died to get work than a house-elf who’d been freed by an owner displeased with them.
“Dobby came to see Professor Dumbledore, sir. You see, sir, it is very difficult for a house-elf who has been dismissed to get a new position, sir, very difficult indeed –”
- Harry Potter and the Goblet of Fire, Chapter 21 (The House-Elf Liberation Front)
That a House-Elf Relocation Office exists is evidence that sometimes house-elves do have to find a new owner, and it seems likely that not all of them were dismissed by owners unhappy with them.
A house-elf would go onto their firstborn son or daughter, and if there are no children, then it goes to another relative (ie; Kreacher would have gone to Bellatrix Lestrange, the oldest of the surviving line of House Black, but Sirius specified that he is owned by Harry) So unless specified, it would go to a relative. I would like to provide a quote, but I can't find a relevant one, so an example will have to do. Also, if there is no relative of any kind, and the will does not specify who will own the elf, the decision would presumably go to the ministry House Elf Legion Office, and either be relocated or set free, depending on if there is a family who is in need of an elf. There is no mention of this in either Fantastic Beasts or Harry Potter stories, so there is no way to prove this in Cannon (JKR hasn't said much on the subject either) But this is the most plausible answer because that is the purpose of the House Elf Legion office, however, if you can find anything in canon, link it and I will gladly edit my response.
No, the house elf is inherited. Sirius Black dies without a heir but Harry inherits the ownership of the elf.
Kreacher's voice had risen to a scream. Harry could think of nothing to say, except, "Kreacher, shut up!" It looked for a moment as though Kreacher was going to choke. He grabbed his throat, his mouth still working furiously, his eyes bulging. After a few seconds of frantic gulping, he threw himself face forward onto the carpet (Aunt Petunia whimpered) and beat the floor with his hands and feet, giving himself over to a violent, but entirely silent, tantrum.
As we can see, Kreacher do not like to obey Harry but he is forced to do.
So House elf are inherited with houses as Dumbledore say.
"You see," Dumbledore said, turning back to Harry and again speaking as though Uncle Vernon had not uttered, "if you have indeed inherited the house, you have also inherited --"Kreacher," finished Dumbledore