[02/20] common/dpaax: fix a memory leak in iterate dir

Message ID tencent_AF91CA18349EF7D3F308719DA86F95915D07@qq.com (mailing list archive)
State Changes Requested, archived
Delegated to: David Marchand
Headers
Series fix memory leaks in error handling |

Checks

Context Check Description
ci/checkpatch success coding style OK

Commit Message

Weiguo Li Feb. 22, 2022, 6:18 p.m. UTC
  When process_dir() fails, the memory to 'subdir' was not freed which
caused a memory leak.

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: