By law, Roy Perez should not have had a gun three years ago when he shot his mother 16 times in their home in Baldwin Park, Calif., killing her, and then went next door and killed a woman and her 4-year-old daughter.

Mr. Perez, who pleaded guilty to three counts of murder and was sentenced last year to life in prison, had a history of mental health issues. As a result, even though in 2004 he legally bought the 9-millimeter Glock 26 handgun he used, at the time of the shootings his name was in a statewide law enforcement database as someone whose gun should be taken away, according to the authorities.

The case highlights a serious vulnerability when it comes to keeping guns out of the hands of the mentally unstable and others, not just in California but across the country.

In the wake of the Tucson shootings, much attention has been paid to various categories of people who are legally barred from buying handguns  those who have been “adjudicated as a mental defective,” have felony convictions, have committed domestic violence misdemeanors and so on. The focus has almost entirely been on gaps in the federal background check system that is supposed to deny guns to these prohibited buyers.