common/dpaax: fix a memory leak in iterate dir

Message ID tencent_F278344ED1229874E4BE954602442E62DE09@qq.com (mailing list archive)
State Superseded, archived
Delegated to: Thomas Monjalon
Headers
Series common/dpaax: fix a memory leak in iterate dir |

Checks

Context Check Description
ci/checkpatch success coding style OK
ci/Intel-compilation success Compilation OK
ci/intel-Testing success Testing PASS
ci/github-robot: build success github build: passed
ci/iol-mellanox-Performance success Performance Testing PASS
ci/iol-broadcom-Functional success Functional Testing PASS
ci/iol-broadcom-Performance success Performance Testing PASS
ci/iol-intel-Performance success Performance Testing PASS
ci/iol-intel-Functional success Functional Testing PASS
ci/iol-aarch64-unit-testing success Testing PASS
ci/iol-aarch64-compile-testing success Testing PASS
ci/iol-x86_64-compile-testing success Testing PASS
ci/iol-abi-testing success Testing PASS
ci/iol-x86_64-unit-testing success Testing PASS

Commit Message

Weiguo Li Feb. 18, 2022, 5:32 p.m. UTC
  Release the memory when error occur.

Fixes: 2183c6f69d7e ("bus/dpaa: add OF parser for device scanning")

Signed-off-by: Weiguo Li <liwg06@foxmail.com>
---
 drivers/common/dpaax/dpaa_of.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
  

Patch

diff --git a/drivers/common/dpaax/dpaa_of.c b/drivers/common/dpaax/dpaa_of.c
index bb2c8fc66b..a827b42efa 100644
--- a/drivers/common/dpaax/dpaa_of.c
+++ b/drivers/common/dpaax/dpaa_of.c
@@ -126,8 +126,10 @@  iterate_dir(struct dirent **d, int num, struct dt_dir *dt)
 				 d[loop]->d_name);
 			subdir->parent = dt;
 			ret = process_dir(subdir->node.node.full_name, subdir);
-			if (ret)
+			if (ret) {
+				free(subdir);
 				return ret;
+			}
 			list_add_tail(&subdir->node.list, &dt->subdirs);
 			break;
 		default: