This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

[参考译文] TDA4VH-Q1:rpmsg_char.c 中具有存储器泄漏

Guru**** 2463330 points


请注意,本文内容源自机器翻译,可能存在语法或其它翻译错误,仅供参考。如需获取准确内容,请参阅链接中的英语原文或自行翻译。

https://e2e.ti.com/support/processors-group/processors/f/processors-forum/1473342/tda4vh-q1-memory-leak-in-rpmsg_char-c

器件型号:TDA4VH-Q1

工具与软件:

尊敬的 TI 论坛:

我们在 rpmsg 库中发现了一个错误。

下面是一个可能修复的补丁:

# * TI RPMsg Char Utility Library
# *
# * Utility Library for accessing rpmsg devices through rpmsg-char driver
# *
# * Copyright (C) 2020 Texas Instruments Incorporated - https://www.ti.com/
# *
# * Redistribution and use in source and binary forms, with or without
# * modification, are permitted provided that the following conditions
# * are met:
# *
# * Redistributions of source code must retain the above copyright
# * notice, this list of conditions and the following disclaimer.
# *
# * Redistributions in binary form must reproduce the above copyright
# * notice, this list of conditions and the following disclaimer in the
# * documentation and/or other materials provided with the distribution.
# *
# * Neither the name of Texas Instruments Incorporated nor the names of
# * its contributors may be used to endorse or promote products derived
# * from this software without specific prior written permission.
# *
# * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
# * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
# * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
# * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
# * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
# * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
# * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
# * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
# * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
# * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
# * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
# *
# */

diff --git a/src/rpmsg_char.c b/src/rpmsg_char.c
index afb4fec..b2886b7 100644
--- a/src/rpmsg_char.c
+++ b/src/rpmsg_char.c
@@ -274,34 +274,29 @@ static int _rpmsg_char_find_ctrldev(struct rpmsg_char_endpt *ept,
 	 * virtio device number and the rpmsg device number.
 	 */
 	sprintf(ctrl_path, "virtio%u.rpmsg_ctrl.0.0", ept->virtio_id);
-	dir = opendir(rpath);
-	if (dir) {
-		/*
-		 * find a directory that matches the rpmsg_ctrl
-		 * form virtio%d.rpmsg_ctrl.0.0
-		 */
-		while ((iter = readdir(dir))) {
-			if (iter->d_type == DT_DIR) {
-				if (!strcmp(iter->d_name, ctrl_path))
-					break;
-			}
+	rewinddir(dir);
+	/*
+		* find a directory that matches the rpmsg_ctrl
+		* form virtio%d.rpmsg_ctrl.0.0
+		*/
+	while ((iter = readdir(dir))) {
+		if (iter->d_type == DT_DIR) {
+			if (!strcmp(iter->d_name, ctrl_path))
+				break;
 		}
-		if (iter) {
-			memset(&fpath, 0, sizeof(fpath));
-			sprintf(fpath, "%s/%s/rpmsg", rpath, iter->d_name);
-			if (check_dir(fpath)) {
-				fprintf(stderr, "%s: rpmsg directory doesn't exist under %s\n",
-					__func__, ept->rpmsg_dev_name);
-				ret = -ENOENT;
-			} else {
-				ret = get_child_dir_suffix(fpath, "rpmsg_ctrl%u", &ctrl_id);
-			}
-		} else {
+	}
+	if (iter) {
+		memset(&fpath, 0, sizeof(fpath));
+		sprintf(fpath, "%s/%s/rpmsg", rpath, iter->d_name);
+		if (check_dir(fpath)) {
+			fprintf(stderr, "%s: rpmsg directory doesn't exist under %s\n",
+				__func__, ept->rpmsg_dev_name);
 			ret = -ENOENT;
+		} else {
+			ret = get_child_dir_suffix(fpath, "rpmsg_ctrl%u", &ctrl_id);
 		}
-	}
-	else  {
-		ret = -errno;
+	} else {
+		ret = -ENOENT;
 	}

 	/* check for backward compatibility if failed */

此致

igmogo_ku

  • 请注意,本文内容源自机器翻译,可能存在语法或其它翻译错误,仅供参考。如需获取准确内容,请参阅链接中的英语原文或自行翻译。

    尊敬的 Igmogu Ku、

    您能否以正式补丁的形式提供此信息、并提供有关错误和修复的详细信息的补丁描述?

    此致

    Suman

  • 请注意,本文内容源自机器翻译,可能存在语法或其它翻译错误,仅供参考。如需获取准确内容,请参阅链接中的英语原文或自行翻译。

    尊敬的 Suman:

    我们发现了这个问题、只想向 TI 报告。 我们尚未在所有可能的场景中对其进行广泛测试。 因此、我将此想法留在这里、以便 TI 可以将其集成到库中(如果您认为有道理)。

    错误的描述如下:

    函数 _rpmsg_char_find_ctrldev 在"rpath"下的目录上迭代两次。 显然、要重新启动迭代、应再次打开目录。 但目录的上一个实例从未关闭,指针丢失。 这会导致内存泄漏。

    我建议的解决办法不是再次重新打开目录、而是倒回目录。

    此致

    igmogo

  • 请注意,本文内容源自机器翻译,可能存在语法或其它翻译错误,仅供参考。如需获取准确内容,请参阅链接中的英语原文或自行翻译。

    您好!

    当然。让我检查并为此提交一个内部 TT。

    此致

    Tarun Mukesh

  • 请注意,本文内容源自机器翻译,可能存在语法或其它翻译错误,仅供参考。如需获取准确内容,请参阅链接中的英语原文或自行翻译。

    您好!

    我已 为此问题提出内部 TT LCPD-43010。

    此致

    Tarun