


Q: Given the following code slice:
```
1 struct pci_bus *pci_acpi_scan_root(struct acpi_pci_root *root)
3     int node = acpi_get_node(root->device->handle);
4     struct acpi_pci_generic_root_info *ri;
5     struct pci_bus *bus, *child;
6     struct acpi_pci_root_ops *root_ops;
7     ri = kzalloc_node(sizeof(*ri), GFP_KERNEL, node);
8     if (!ri)
10         return NULL;
12     root_ops = kzalloc_node(sizeof(*root_ops), GFP_KERNEL, node);
13     if (!root_ops)
15         return NULL;
17     ri->cfg = pci_acpi_setup_ecam_mapping(root);
18     if (!ri->cfg)
20         kfree(ri);
21         kfree(root_ops);
22         return NULL;
24     root_ops->release_info = pci_acpi_generic_release_info;
25     root_ops->prepare_resources = pci_acpi_root_prepare_resources;
26     root_ops->pci_ops = &ri->cfg->ops->pci_ops;
27     bus = acpi_pci_root_create(root, root_ops, &ri->common, ri->cfg);
28     if (!bus)
30         return NULL;
32     pci_bus_size_bridges(bus);
33     pci_bus_assign_resources(bus);
34     list_for_each_entry(, , ) pcie_bus_configure_settings(child);
35     return bus;```
which has a CWE-401 vulnerability at line:
```
15         return NULL;
```
Please generate the patch for the vulnerability. Please follow the patch format in the exemplars.
The patching can be done in two steps.

Step 1. Root Cause Analysis: Looking at the given vulnerable code line and its context, the CWE-401 (Improper Release of Memory Before Removing Last Reference) vulnerability exists in the code because the memory allocated for `ri` is not freed before returning `NULL` at line 15. This leads to a memory leak.

Step 2. Fixing Strategy. A common fixing strategy is to ensure that all allocated memory is freed before returning `NULL`. This can be done by adding a call to `kfree(ri)` before returning `NULL`. Therefore, the patch should be:
```
<     {
<         return NULL;
---
>     {
>         kfree(ri);
>         return NULL;
```
This patch ensures that the memory allocated for `ri` is properly freed before returning `NULL`, preventing the memory leak.