已关闭
[Bug-Report|缺陷反馈]: [工具检测] ops-math 仓 not_equal / floor_div 样例未判空即 aclrtFree 空指针,检测报 illegal free() #3225
Goldfish_of_Siris创建于  9月18日关闭于  9月20日
Goldfish_of_Siris
Goldfish_of_Siris
9月18日 创建

Thanks for sending an issue! Please fill in the following template to help quickly solve your problem.

Describe the current behavior / 问题描述 (Mandatory / 必填)*

msSanitizer 扫网时,两个算子的「tensor + 标量」样例在收尾释放 device 资源处未判空即 aclrtFree(nullptr),工具如实上报 illegal free()(memcheck、initcheck 各 1 条)。分析确认无功能影响,但不符合安全编程规范。

算子 样例文件 声明/释放行 第二输入
not_equal math/not_equal/examples/test_aclnn_ne_scalar.cpp :93 / :151 aclScalar(:106)
not_equal math/not_equal/examples/test_aclnn_inplace_ne_scalar.cpp :93 / :151 aclScalar(:106)
floor_div math/floor_div/examples/test_aclnn_floor_divides.cpp :89 / :171 aclScalar(:101)

根因:第二输入为标量(aclCreateScalar,不占 device 内存),otherDeviceAddr 声明后一直为 nullptr,未实际申请内存赋值,但收尾沿用了 tensor 版的释放模板:void *otherDeviceAddr = nullptr; → aclrtFree(otherDeviceAddr);。

Environment / 环境信息 (Mandatory / 必填)*

项目 值
硬件/卡 Ascend950PR,NPU 3
CANN 版本 9.1.0(社区商版本,下载链接:https://www.hiascend.com/developer/download/community/result?module=cann&cann=9.1.0)
算子仓库 ops-math,分支 9.1.0
编译/安装 bash build.sh --pkg --soc=ascend950 --ops=<算子> --mssanitizer -j128 → ./build_out/cann-ops-math-custom_linux-x86_64.run
样例 bash build.sh --run_example <算子> eager cust --soc=ascend950 --example_name=<样例名>
检测 cd build && mssanitizer -t <tool> --log-level=error -- ./test_aclnn_<算子>

Steps to reproduce the issue / 重现步骤 (Mandatory / 必填)*

source <CANN 安装路径>/set_env.sh; export MSSANITIZER_ENABLE_DEBUG_LOG=1
cd ~/gitcode/ops-math
bash build.sh --pkg --soc=ascend950 --ops=not_equal --mssanitizer -j128 && ./build_out/cann-ops-math-custom_linux-x86_64.run
bash build.sh --run_example not_equal eager cust --soc=ascend950 --example_name=ne_scalar
cd build && mssanitizer -t memcheck --log-level=error -- ./test_aclnn_not_equal
# floor_div 同理:--ops=floor_div、--example_name=floor_divides、./test_aclnn_floor_div

--example_name 只切换样例源码、产物二进制名固定,多样例需逐个重建后再检测。

Describe the expected behavior / 预期结果 (Mandatory / 必填)*

请修正样例的 device 资源释放, 释放前判空 if (otherDeviceAddr != nullptr) { aclrtFree(otherDeviceAddr); }。
建议同时排查同类样例(第二输入用 aclCreateScalar、收尾仍照抄 tensor 版释放模板者)。

工具输出:[MemoryDataCollect.cpp:112] WARN free addr:0 is not found, maybe the memory is already freed, infoSrc:3 + ====== ERROR: illegal free() / at 0x0 on GM / code in <unknown> (serialNo:90)。
原始日志(见附件目录 test_result/issue/issue_样例未判空即aclrtFree空指针/):not_equal 的 mssanitizer_origin_{memcheck,initcheck}_20260911_201438.txt(inplace_ne_scalar 组)、..._201835.txt(ne_scalar 组)、..._20260915_1713_ne_tensor_对照.txt;floor_div 的 mssanitizer_origin_{memcheck,initcheck}_20260911_170910.txt。

附件:issue_样例未判空即aclrtFree空指针.zip

likedislike
xujiachen8成员
9月18日 评论:

您好,感谢反馈!

我们核对了 ops-math 9.1.0 分支中的三个相关样例。otherDeviceAddr 均初始化为 nullptr,而标量输入实际通过 aclCreateScalar 创建,没有为该指针申请 device 内存;收尾阶段继续调用 aclrtFree(otherDeviceAddr),因此会触发 msSanitizer 报告的 illegal free()。从现有代码和日志看,这属于样例资源释放问题,不影响算子计算结果。

当前 master 分支中的 floor_div 样例已不再保留和释放该无效指针;两个 not_equal 标量样例仍存在同类调用。可行的处理方向是移除从未分配的指针及对应释放,或在释放前进行非空判断,并同步检查其他标量输入样例是否沿用了相同模板。我们会继续确认责任归属和后续处理方式。

likedislike
Xxujiachen8成员
9月20日 将 ly_cann_coder 设为负责人
Xxujiachen8成员
9月20日 关联了pull request:[BugFix] 修复 not_equal 和 floor_div 标量样例的空指针释放
Xxujiachen8成员
9月20日 关联了pull request:[BugFix] 修复 not_equal 标量样例的空指针释放
Xxujiachen8成员
9月20日 删除了关联的pull request:[BugFix] 修复 not_equal 和 floor_div 标量样例的空指针释放
Xxujiachen8成员
9月20日 关联了pull request:[BugFix] 修复 not_equal 和 floor_div 标量样例的空指针释放
Ssongkai111成员
9月20日 issue状态由 进行中 改变为 已完成
Ssongkai111成员
9月20日 关闭了 issue