运行valgrind node
后,Node似乎中止了一个与系统调用有关的错误。
我在macOS Sierra,Node v8.2.1。
$ valgrind `which node` test-pass.js
==17115== Memcheck, a memory error detector
==17115== Copyright (C) 2002-2017, and GNU GPL'd, by Julian Seward et al.
==17115== Using Valgrind-3.13.0 and LibVEX; rerun with -h for copyright info
==17115== Command: /Users/junon/n/bin/node test-pass.js
==17115==
==17115== Syscall param msg->desc.port.name points to uninitialised byte(s)
==17115== at 0x10352B34A: mach_msg_trap (in /usr/lib/system/libsystem_kernel.dylib)
==17115== by 0x10352A796: mach_msg (in /usr/lib/system/libsystem_kernel.dylib)
==17115== by 0x103524485: task_set_special_port (in /usr/lib/system/libsystem_kernel.dylib)
==17115== by 0x1036C010E: _os_trace_create_debug_control_port (in /usr/lib/system/libsystem_trace.dylib)
==17115== by 0x1036C0458: _libtrace_init (in /usr/lib/system/libsystem_trace.dylib)
==17115== by 0x1029B29DF: libSystem_initializer (in /usr/lib/libSystem.B.dylib)
==17115== by 0x1021ECA1A: ImageLoaderMachO::doModInitFunctions(ImageLoader::LinkContext const&) (in /usr/lib/dyld)
==17115== by 0x1021ECC1D: ImageLoaderMachO::doInitialization(ImageLoader::LinkContext const&) (in /usr/lib/dyld)
==17115== by 0x1021E84A9: ImageLoader::recursiveInitialization(ImageLoader::LinkContext const&, unsigned int, char const*, ImageLoader::InitializerTimingList&, ImageLoader::UninitedUpwards&) (in /usr/lib/dyld)
==17115== by 0x1021E8440: ImageLoader::recursiveInitialization(ImageLoader::LinkContext const&, unsigned int, char const*, ImageLoader::InitializerTimingList&, ImageLoader::UninitedUpwards&) (in /usr/lib/dyld)
==17115== by 0x1021E7523: ImageLoader::processInitializers(ImageLoader::LinkContext const&, unsigned int, ImageLoader::InitializerTimingList&, ImageLoader::UninitedUpwards&) (in /usr/lib/dyld)
==17115== by 0x1021E75B8: ImageLoader::runInitializers(ImageLoader::LinkContext const&, ImageLoader::InitializerTimingList&) (in /usr/lib/dyld)
==17115== Address 0x7fff5fbfda8c is on thread 1's stack
==17115== in frame #2, created by task_set_special_port (???:)
==17115==
Assertion failed: (process_title.len + 1 == size), function uv_setup_args, file ../deps/uv/src/unix/proctitle.c, line 58.
==17115==
==17115== Process terminating with default action of signal 6 (SIGABRT)
==17115== at 0x103532D72: __pthread_sigmask (in /usr/lib/system/libsystem_kernel.dylib)
==17115== by 0x1034404A8: __abort (in /usr/lib/system/libsystem_c.dylib)
==17115== by 0x10344042E: abort (in /usr/lib/system/libsystem_c.dylib)
==17115== by 0x103407892: __assert_rtn (in /usr/lib/system/libsystem_c.dylib)
==17115== by 0x100BEC7B6: uv_setup_args (in /Users/junon/n/bin/node)
==17115== by 0x100A7EC9F: node::Start(int, char**) (in /Users/junon/n/bin/node)
==17115== by 0x100000E33: (below main) (in /Users/junon/n/bin/node)
==17115==
==17115== HEAP SUMMARY:
==17115== in use at exit: 71,518 bytes in 369 blocks
==17115== total heap usage: 469 allocs, 100 frees, 108,584 bytes allocated
==17115==
==17115== LEAK SUMMARY:
==17115== definitely lost: 0 bytes in 0 blocks
==17115== indirectly lost: 0 bytes in 0 blocks
==17115== possibly lost: 7,272 bytes in 115 blocks
==17115== still reachable: 10,270 bytes in 98 blocks
==17115== suppressed: 53,976 bytes in 156 blocks
==17115== Rerun with --leak-check=full to see details of leaked memory
==17115==
==17115== For counts of detected and suppressed errors, rerun with: -v
==17115== Use --track-origins=yes to see where uninitialised values come from
==17115== ERROR SUMMARY: 1 errors from 1 contexts (suppressed: 1 from 1)
[1] 17115 abort valgrind `which node` test-pass.js
你应该如何在Node.js的C ++附加组件中检查内存泄漏?我看到提到在2010年左右使用node_g
,但我的安装中似乎缺少该可执行文件。