diff mbox

[U-Boot] pci: avoid memory leak

Message ID 20170508184016.24404-1-xypron.glpk@gmx.de
State Accepted
Commit c42640c74813f5c9aa9d0d3bdad5ebd565bdfcdc
Delegated to: Tom Rini
Headers show

Commit Message

Heinrich Schuchardt May 8, 2017, 6:40 p.m. UTC
strdup uses malloc to allocate memory for str.
If we cannot bind to the generic driver we should release
the memory.

The problem was indicated by clang scan-build.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
---
 drivers/pci/pci-uclass.c | 1 +
 1 file changed, 1 insertion(+)

Comments

Bin Meng May 9, 2017, 2:24 a.m. UTC | #1
On Tue, May 9, 2017 at 2:40 AM, Heinrich Schuchardt <xypron.glpk@gmx.de> wrote:
> strdup uses malloc to allocate memory for str.
> If we cannot bind to the generic driver we should release
> the memory.
>
> The problem was indicated by clang scan-build.
>
> Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
> ---
>  drivers/pci/pci-uclass.c | 1 +
>  1 file changed, 1 insertion(+)
>

Reviewed-by: Bin Meng <bmeng.cn@gmail.com>
Tom Rini May 12, 2017, 5:21 p.m. UTC | #2
On Mon, May 08, 2017 at 08:40:16PM +0200, xypron.glpk@gmx.de wrote:

> strdup uses malloc to allocate memory for str.
> If we cannot bind to the generic driver we should release
> the memory.
> 
> The problem was indicated by clang scan-build.
> 
> Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
> Reviewed-by: Bin Meng <bmeng.cn@gmail.com>

Applied to u-boot/master, thanks!
diff mbox

Patch

diff --git a/drivers/pci/pci-uclass.c b/drivers/pci/pci-uclass.c
index 40f59c0c4c..504d7e3bb1 100644
--- a/drivers/pci/pci-uclass.c
+++ b/drivers/pci/pci-uclass.c
@@ -660,6 +660,7 @@  static int pci_find_and_bind_driver(struct udevice *parent,
 	ret = device_bind_driver(parent, drv, str, devp);
 	if (ret) {
 		debug("%s: Failed to bind generic driver: %d\n", __func__, ret);
+		free(str);
 		return ret;
 	}
 	debug("%s: No match found: bound generic driver instead\n", __func__);