From bf026fa41a26ce76a7ddedb698b81d0fbfd48714 Mon Sep 17 00:00:00 2001 From: kochi Date: Tue, 13 May 2003 13:29:00 +0000 Subject: Fix a reference count problem that may cause unexpected memory free etc. This is a backport of the latest ACPI CA that has a fix for this. --- sys/dev/acpi/acpica/Subsystem/nsalloc.c | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) (limited to 'sys/dev') diff --git a/sys/dev/acpi/acpica/Subsystem/nsalloc.c b/sys/dev/acpi/acpica/Subsystem/nsalloc.c index 1335ed9de84..604837e9b42 100644 --- a/sys/dev/acpi/acpica/Subsystem/nsalloc.c +++ b/sys/dev/acpi/acpica/Subsystem/nsalloc.c @@ -115,7 +115,7 @@ *****************************************************************************/ #include -__KERNEL_RCSID(0, "$NetBSD: nsalloc.c,v 1.7 2003/05/13 13:07:13 kochi Exp $"); +__KERNEL_RCSID(0, "$NetBSD: nsalloc.c,v 1.8 2003/05/13 13:29:00 kochi Exp $"); #define __NSALLOC_C__ @@ -457,6 +457,7 @@ AcpiNsDeleteChildren ( { ACPI_NAMESPACE_NODE *ChildNode; ACPI_NAMESPACE_NODE *NextNode; + ACPI_NAMESPACE_NODE *Node; UINT8 Flags; @@ -505,6 +506,25 @@ AcpiNsDeleteChildren ( * Detach an object if there is one, then free the child node */ AcpiNsDetachObject (ChildNode); + + /* + * Decrement the reference count(s) of all parents up to + * the root! (counts were incremented when the node was created) + */ + Node = ChildNode; + while ((Node = AcpiNsGetParentNode (Node)) != NULL) { + Node->ReferenceCount--; + } + + /* There should be only one reference remaining on this node */ + + if (ChildNode->ReferenceCount != 1) { + ACPI_REPORT_WARNING (("Existing references (%d) on node being deleted (%p)\n", + ChildNode->ReferenceCount, ChildNode)); + } + + /* Now we can delete the node */ + ACPI_MEM_FREE (ChildNode); /* And move on to the next child in the list */ -- cgit