You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

macOS下AddressSanitizer与leaks工具无法检测内存泄漏求助

macOS下AddressSanitizer与leaks工具无法检测内存泄漏的问题

现象描述

1. AddressSanitizer运行报错

用-fsanitize=address编译后的程序运行时,仅返回以下错误,完全没有内存泄漏提示:

a.out(45811,0x7ff856c70680) malloc: nano zone abandoned due to inability to reserve vm space.

2. leaks工具检测报错

使用leaks工具分析进程时,返回一系列错误信息:

a.out(46256,0x7ff856c70680) malloc: nano zone abandoned due to inability to reserve vm space.
a.out(46256) MallocStackLogging: could not tag MSL-related memory as no_footprint, so those pages will be included in process footprint - (null)
a.out(46256) MallocStackLogging: zone[0] is not the normal default zone so can't turn on lite mode.
Can't examine target process's malloc zone asan_0x1108535b8, so memory analysis will be incomplete or incorrect.
Reason: for security, cannot load non-system library /Library/Developer/CommandLineTools/usr/lib/clang/16/lib/darwin/libclang_rt.asan_osx_dynamic.dylib

测试代码

为验证问题,使用一段存在明确内存泄漏的测试代码:

#include <stdlib.h>
int main(void)
{
    char *str;

    str = (char *)malloc(10*sizeof(char));
    str[0] = 'a';
    str[1] = 0;
    exit(0);
}

编译命令

编译代码使用的命令:

cc -Wextra -Wall -Werror -fsanitize=address main.c

疑问

这段代码在Ubuntu系统中用AddressSanitizer可以正常检测到内存泄漏,但在macOS下始终无法触发泄漏提示,仅返回上述错误。请问这一问题的原因是什么?

内容的提问来源于stack exchange,提问作者Jose

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.13 23:52:41