我正在用 c++ 编写代码,使用 text wrangler 编写代码并使用命令行中的 g++ 编译它。我希望能够检测我的代码是否有任何内存泄漏。我尝试过使用 valgrind,但它似乎不适合特立独行者,我尝试运行“leak a.out”,其中 a.out 是运行“g++ *.h *.cc”的结果,但我收到错误消息“leaks”找不到您有权访问的名称类似于“a.out”的进程“关于如何进行内存泄漏检查的任何想法?
这是输出
==1317== Memcheck, a memory error detector
==1317== Copyright (C) 2002-2012, and GNU GPL'd, by Julian Seward et al.
==1317== Using Valgrind-3.8.1 and LibVEX; rerun with -h for copyright info
==1317== Command: ./a.out
==1317==
==1317== WARNING: Support on MacOS 10.8 is experimental and mostly broken.
==1317== WARNING: Expect incorrect results, assertions and crashes.
==1317== WARNING: In particular, Memcheck on 32-bit programs will fail to
==1317== WARNING: detect any errors associated with heap-allocated data.
==1317==
--1317-- Valgrind options:
--1317-- --leak-check=full
--1317-- -v
--1317-- Contents of /proc/version:
--1317-- can't open /proc/version
--1317-- Arch and hwcaps: AMD64, amd64-sse3-cx16-avx
--1317-- Page sizes: currently 4096, max supported 4096
--1317-- Valgrind library directory: /usr/local/lib/valgrind
--1317-- ./a.out (rx at 0x100000000, rw at 0x100002000)
--1317-- reading syms from primary file (14 7)
--1317-- dSYM directory is missing; consider using --dsymutil=yes
--1317-- /usr/lib/dyld (rx at 0x7fff5fc00000, rw at 0x7fff5fc34000)
--1317-- reading syms from primary file (6 1183)
--1317-- Scheduler: using generic scheduler lock implementation.
--1317-- Reading suppressions file: /usr/local/lib/valgrind/default.supp
==1317== embedded gdbserver: reading from /var/folders/b8/2knh_y5j1q9gn4874f4c10yh0000gn/T//vgdb-pipe-from-vgdb-to-1317-by-joelmalchiondo-on-???
==1317== embedded gdbserver: writing to /var/folders/b8/2knh_y5j1q9gn4874f4c10yh0000gn/T//vgdb-pipe-to-vgdb-from-1317-by-joelmalchiondo-on-???
==1317== embedded gdbserver: shared mem /var/folders/b8/2knh_y5j1q9gn4874f4c10yh0000gn/T//vgdb-pipe-shared-mem-vgdb-1317-by-joelmalchiondo-on-???
==1317==
==1317== TO CONTROL THIS PROCESS USING vgdb (which you probably
==1317== don't want to do, unless you know exactly what you're doing,
==1317== or are doing some strange experiment):
==1317== /usr/local/lib/valgrind/../../bin/vgdb --pid=1317 ...command...
==1317==
==1317== TO DEBUG THIS PROCESS USING GDB: start GDB like this
==1317== /path/to/gdb ./a.out
==1317== and then give GDB the following command
==1317== target remote | /usr/local/lib/valgrind/../../bin/vgdb --pid=1317
==1317== --pid is optional if only one valgrind process is running
==1317==
--1317-- REDIR: 0x7fff5fc1b798 (arc4random) redirected to 0x238056b0e (???)
--1317-- REDIR: 0x7fff5fc21560 (strcmp) redirected to 0x238056a70 (???)
--1317-- REDIR: 0x7fff5fc1b560 (strlen) redirected to 0x238056a3f (???)
--1317-- REDIR: 0x7fff5fc1b4c0 (strcpy) redirected to 0x238056a8c (???)
--1317-- REDIR: 0x7fff5fc1ec4f (strcat) redirected to 0x238056a50 (???)
--1317-- /usr/local/lib/valgrind/vgpreload_core-amd64-darwin.so (rx at 0x1000, rw at 0x2000)
--1317-- reading syms from primary file (3 31)
--1317-- dSYM= /usr/local/lib/valgrind/vgpreload_core-amd64-darwin.so.dSYM/Contents/Resources/DWARF/vgpreload_core-amd64-darwin.so
--1317-- reading dwarf3 from dsyms file
--1317-- /usr/local/lib/valgrind/vgpreload_memcheck-amd64-darwin.so (rx at 0x4000, rw at 0x8000)
--1317-- reading syms from primary file (47 244)
--1317-- dSYM= /usr/local/lib/valgrind/vgpreload_memcheck-amd64-darwin.so.dSYM/Contents/Resources/DWARF/vgpreload_memcheck-amd64-darwin.so
--1317-- reading dwarf3 from dsyms file
UNKNOWN fcntl 61!--1317-- /usr/lib/libc++.1.dylib (rx at 0xc000, rw at 0x5f000)
--1317-- reading syms from primary file (2070 1507)
UNKNOWN fcntl 61!--1317-- /usr/lib/libSystem.B.dylib (rx at 0xba000, rw at 0xbc000)
--1317-- reading syms from primary file (31 4)
UNKNOWN fcntl 61!--1317-- /usr/lib/libc++abi.dylib (rx at 0xc2000, rw at 0xec000)
--1317-- reading syms from primary file (322 178)
UNKNOWN fcntl 61!--1317-- /usr/lib/system/libcache.dylib (rx at 0xf9000, rw at 0xfe000)
--1317-- reading syms from primary file (29 24)
UNKNOWN fcntl 61!--1317-- /usr/lib/system/libcommonCrypto.dylib (rx at 0x102000, rw at 0x10d000)
--1317-- reading syms from primary file (203 183)
UNKNOWN fcntl 61!--1317-- /usr/lib/system/libcompiler_rt.dylib (rx at 0x11a000, rw at 0x122000)
--1317-- reading syms from primary file (454 8)
UNKNOWN fcntl 61!--1317-- /usr/lib/system/libcopyfile.dylib (rx at 0x12d000, rw at 0x135000)
--1317-- reading syms from primary file (11 28)
UNKNOWN fcntl 61!--1317-- /usr/lib/system/libcorecrypto.dylib (rx at 0x13b000, rw at 0x18a000)
--1317-- reading syms from primary file (341 430)
UNKNOWN fcntl 61!--1317-- /usr/lib/system/libdispatch.dylib (rx at 0x19a000, rw at 0x1b5000)
--1317-- reading syms from primary file (176 737)
UNKNOWN fcntl 61!--1317-- /usr/lib/system/libdyld.dylib (rx at 0x1ce000, rw at 0x1d2000)
--1317-- reading syms from primary file (78 96)
UNKNOWN fcntl 61!--1317-- /usr/lib/system/libkeymgr.dylib (rx at 0x1d8000, rw at 0x1d9000)
--1317-- reading syms from primary file (12 4)
UNKNOWN fcntl 61!--1317-- /usr/lib/system/liblaunch.dylib (rx at 0x1dd000, rw at 0x1e5000)
--1317-- reading syms from primary file (112 1)
UNKNOWN fcntl 61!--1317-- /usr/lib/system/libmacho.dylib (rx at 0x1ec000, rw at 0x1f2000)
--1317-- reading syms from primary file (86 1)
UNKNOWN fcntl 61!--1317-- /usr/lib/system/libquarantine.dylib (rx at 0x1f7000, rw at 0x1fa000)
--1317-- reading syms from primary file (66 32)
UNKNOWN fcntl 61!--1317-- /usr/lib/system/libremovefile.dylib (rx at 0x1ff000, rw at 0x201000)
--1317-- reading syms from primary file (15 4)
UNKNOWN fcntl 61!--1317-- /usr/lib/system/libsystem_asl.dylib (rx at 0x206000, rw at 0x218000)
--1317-- reading syms from primary file (127 106)
UNKNOWN fcntl 61!--1317-- /usr/lib/system/libsystem_blocks.dylib (rx at 0x221000, rw at 0x223000)
--1317-- reading syms from primary file (25 23)
UNKNOWN fcntl 61!--1317-- /usr/lib/system/libsystem_c.dylib (rx at 0x227000, rw at 0x2b1000)
--1317-- reading syms from primary file (1288 783)
UNKNOWN fcntl 61!--1317-- /usr/lib/system/libsystem_configuration.dylib (rx at 0x2dc000, rw at 0x2df000)
--1317-- reading syms from primary file (27 58)
UNKNOWN fcntl 61!--1317-- /usr/lib/system/libsystem_dnssd.dylib (rx at 0x2e4000, rw at 0x2ed000)
--1317-- reading syms from primary file (68 34)
UNKNOWN fcntl 61!--1317-- /usr/lib/system/libsystem_info.dylib (rx at 0x2f3000, rw at 0x31b000)
--1317-- reading syms from primary file (526 526)
UNKNOWN fcntl 61!--1317-- /usr/lib/system/libsystem_kernel.dylib (rx at 0x330000, rw at 0x34d000)
--1317-- reading syms from primary file (931 2486)
UNKNOWN fcntl 61!--1317-- /usr/lib/system/libsystem_m.dylib (rx at 0x36f000, rw at 0x39f000)
--1317-- reading syms from primary file (573 1)
UNKNOWN fcntl 61!--1317-- /usr/lib/system/libsystem_malloc.dylib (rx at 0x3a9000, rw at 0x3c5000)
--1317-- reading syms from primary file (102 199)
UNKNOWN fcntl 61!--1317-- /usr/lib/system/libsystem_network.dylib (rx at 0x3ce000, rw at 0x3f6000)
--1317-- reading syms from primary file (168 1053)
UNKNOWN fcntl 61!--1317-- /usr/lib/system/libsystem_notify.dylib (rx at 0x411000, rw at 0x41b000)
--1317-- reading syms from primary file (137 48)
UNKNOWN fcntl 61!--1317-- /usr/lib/system/libsystem_platform.dylib (rx at 0x423000, rw at 0x42a000)
--1317-- reading syms from primary file (114 1463)
UNKNOWN fcntl 61!--1317-- /usr/lib/system/libsystem_pthread.dylib (rx at 0x43c000, rw at 0x444000)
--1317-- reading syms from primary file (137 54)
UNKNOWN fcntl 61!--1317-- /usr/lib/system/libsystem_sandbox.dylib (rx at 0x44f000, rw at 0x451000)
--1317-- reading syms from primary file (61 8)
UNKNOWN fcntl 61!--1317-- /usr/lib/system/libsystem_stats.dylib (rx at 0x455000, rw at 0x45a000)
--1317-- reading syms from primary file (20 42)
UNKNOWN fcntl 61!--1317-- /usr/lib/system/libunc.dylib (rx at 0x460000, rw at 0x462000)
--1317-- reading syms from primary file (31 4)
UNKNOWN fcntl 61!--1317-- /usr/lib/system/libunwind.dylib (rx at 0x467000, rw at 0x46d000)
--1317-- reading syms from primary file (102 52)
UNKNOWN fcntl 61!--1317-- /usr/lib/system/libxpc.dylib (rx at 0x473000, rw at 0x498000)
--1317-- reading syms from primary file (349 818)
UNKNOWN fcntl 61!--1317-- /usr/lib/libobjc.A.dylib (rx at 0x4b4000, rw at 0x662000)
--1317-- reading syms from primary file (342 735)
UNKNOWN fcntl 61!--1317-- /usr/lib/libauto.dylib (rx at 0x682000, rw at 0x6c5000)
--1317-- reading syms from primary file (68 742)
UNKNOWN fcntl 61!--1317-- /usr/lib/libDiagnosticMessagesClient.dylib (rx at 0x6dc000, rw at 0x6de000)
--1317-- reading syms from primary file (21 14)
eq_SyscallStatus:
{78 0 43}
{78 0 40}
valgrind: m_syswrap/syswrap-main.c:380 (Bool eq_SyscallStatus(SyscallStatus *, SyscallStatus *)): the 'impossible' happened.
==1317== at 0x23803C34B: ???
==1317== by 0x23803C2F0: ???
==1317== by 0x2380B1983: ???
==1317== by 0x2380B107D: ???
==1317== by 0x2380AF5F2: ???
==1317== by 0x2380AD72A: ???
==1317== by 0x2380BF1C0: ???
sched status:
running_tid=1
Thread 1: status = VgTs_Runnable
==1317== at 0x341966: _kernelrpc_mach_vm_map_trap (in /usr/lib/system/libsystem_kernel.dylib)
==1317== by 0x3ABF6F: allocate_pages (in /usr/lib/system/libsystem_malloc.dylib)
==1317== by 0x3ABA11: create_scalable_zone (in /usr/lib/system/libsystem_malloc.dylib)
==1317== by 0x3B93ED: _malloc_initialize (in /usr/lib/system/libsystem_malloc.dylib)
==1317== by 0x3BA27D: malloc (in /usr/lib/system/libsystem_malloc.dylib)
==1317== by 0x7FFF5FC12D4F: malloc (in /usr/lib/dyld)
==1317== by 0x7FFF5FC1A3BD: operator new(unsigned long) (in /usr/lib/dyld)
==1317== by 0x7FFF5FC090EC: std::__1::__split_buffer<char const* (*)(dyld_image_states, unsigned int, dyld_image_info const*), std::__1::allocator<char const* (*)(dyld_image_states, unsigned int, dyld_image_info const*)>&>::__split_buffer(unsigned long, unsigned long, std::__1::allocator<char const* (*)(dyld_image_states, unsigned int, dyld_image_info const*)>&) (in /usr/lib/dyld)
==1317== by 0x7FFF5FC08A44: std::__1::vector<char const* (*)(dyld_image_states, unsigned int, dyld_image_info const*), std::__1::allocator<char const* (*)(dyld_image_states, unsigned int, dyld_image_info const*)> >::insert(std::__1::__wrap_iter<char const* (* const*)(dyld_image_states, unsigned int, dyld_image_info const*)>, char const* (* const&)(dyld_image_states, unsigned int, dyld_image_info const*)) (in /usr/lib/dyld)
==1317== by 0x7FFF5FC0426B: dyld::registerImageStateBatchChangeHandler(dyld_image_states, char const* (*)(dyld_image_states, unsigned int, dyld_image_info const*)) (in /usr/lib/dyld)
==1317== by 0x1D08F0: dyld_register_image_state_change_handler (in /usr/lib/system/libdyld.dylib)
==1317== by 0x1D06B1: _dyld_initializer (in /usr/lib/system/libdyld.dylib)
==1317== by 0xBBA9D: libSystem_initializer (in /usr/lib/libSystem.B.dylib)
==1317== by 0x7FFF5FC11C2D: ImageLoaderMachO::doModInitFunctions(ImageLoader::LinkContext const&) (in /usr/lib/dyld)
==1317== by 0x7FFF5FC11DB9: ImageLoaderMachO::doInitialization(ImageLoader::LinkContext const&) (in /usr/lib/dyld)
==1317== by 0x7FFF5FC0EA61: ImageLoader::recursiveInitialization(ImageLoader::LinkContext const&, unsigned int, ImageLoader::InitializerTimingList&) (in /usr/lib/dyld)
==1317== by 0x7FFF5FC0E9EA: ImageLoader::recursiveInitialization(ImageLoader::LinkContext const&, unsigned int, ImageLoader::InitializerTimingList&) (in /usr/lib/dyld)
==1317== by 0x7FFF5FC0E8F5: ImageLoader::runInitializers(ImageLoader::LinkContext const&, ImageLoader::InitializerTimingList&) (in /usr/lib/dyld)
==1317== by 0x7FFF5FC021B6: dyld::initializeMainExecutable() (in /usr/lib/dyld)
==1317== by 0x7FFF5FC0555F: dyld::_main(macho_header const*, unsigned long, int, char const**, char const**, char const**, unsigned long*) (in /usr/lib/dyld)
==1317== by 0x7FFF5FC0127A: dyldbootstrap::start(macho_header const*, int, char const**, long, macho_header const*, unsigned long*) (in /usr/lib/dyld)
==1317== by 0x7FFF5FC0105D: _dyld_start (in /usr/lib/dyld)
Note: see also the FAQ in the source distribution.
It contains workarounds to several common problems.
In particular, if Valgrind aborted or crashed after
identifying problems in your program, there's a good chance
that fixing those problems will prevent Valgrind aborting or
crashing, especially if it happened in m_mallocfree.c.
If that doesn't help, please report this bug to: www.valgrind.org
In the bug report, send all the above text, the valgrind
version, and what OS and version you are using. Thanks.
最佳答案
Valgrind 可以运行您的程序并使用
进行完整的内存检查valgrind --leak-check=full -v ./a.out
它将运行您的程序并为您提供有关内存使用情况和可能泄漏的详细信息。此外,您应该使用调试符号编译您的程序:
g++ -g *.h *.cc
然后追溯内存泄漏的原因可能很困难。你可以查看这篇文章:
http://www.cprogramming.com/debugging/valgrind.html
或
http://valgrind.org/docs/manual/mc-manual.html#mc-manual.leaks
关于Mac OSX 上的 c++ 内存泄漏检测,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19699683/
作为我的Rails应用程序的一部分,我编写了一个小导入程序,它从我们的LDAP系统中吸取数据并将其塞入一个用户表中。不幸的是,与LDAP相关的代码在遍历我们的32K用户时泄漏了大量内存,我一直无法弄清楚如何解决这个问题。这个问题似乎在某种程度上与LDAP库有关,因为当我删除对LDAP内容的调用时,内存使用情况会很好地稳定下来。此外,不断增加的对象是Net::BER::BerIdentifiedString和Net::BER::BerIdentifiedArray,它们都是LDAP库的一部分。当我运行导入时,内存使用量最终达到超过1GB的峰值。如果问题存在,我需要找到一些方法来更正我的代
我的瘦服务器配置了nginx,我的ROR应用程序正在它们上运行。在我发布代码更新时运行thinrestart会给我的应用程序带来一些停机时间。我试图弄清楚如何优雅地重启正在运行的Thin实例,但找不到好的解决方案。有没有人能做到这一点? 最佳答案 #Restartjustthethinserverdescribedbythatconfigsudothin-C/etc/thin/mysite.ymlrestartNginx将继续运行并代理请求。如果您将Nginx设置为使用多个上游服务器,例如server{listen80;server
我想设置一个默认日期,例如实际日期,我该如何设置?还有如何在组合框中设置默认值顺便问一下,date_field_tag和date_field之间有什么区别? 最佳答案 试试这个:将默认日期作为第二个参数传递。youcorrectlysetthedefaultvalueofcomboboxasshowninyourquestion. 关于ruby-on-rails-date_field_tag,如何设置默认日期?[rails上的ruby],我们在StackOverflow上找到一个类似的问
我将我的Rails应用程序部署到OpenShift,它运行良好,但我无法在生产服务器上运行“Rails控制台”。它给了我这个错误。我该如何解决这个问题?我尝试更新rubygems,但它也给出了权限被拒绝的错误,我也无法做到。railsc错误:Warning:You'reusingRubygems1.8.24withSpring.UpgradetoatleastRubygems2.1.0andrun`gempristine--all`forbetterstartupperformance./opt/rh/ruby193/root/usr/share/rubygems/rubygems
我收到这个错误:RuntimeError(自动加载常量Apps时检测到循环依赖当我使用多线程时。下面是我的代码。为什么会这样?我尝试多线程的原因是因为我正在编写一个HTML抓取应用程序。对Nokogiri::HTML(open())的调用是一个同步阻塞调用,需要1秒才能返回,我有100,000多个页面要访问,所以我试图运行多个线程来解决这个问题。有更好的方法吗?classToolsController0)app.website=array.join(',')putsapp.websiteelseapp.website="NONE"endapp.saveapps=Apps.order("
我正在尝试从Postgresql表(table1)中获取数据,该表由另一个相关表(property)的字段(table2)过滤。在纯SQL中,我会这样编写查询:SELECT*FROMtable1JOINtable2USING(table2_id)WHEREtable2.propertyLIKE'query%'这工作正常:scope:my_scope,->(query){includes(:table2).where("table2.property":query)}但我真正需要的是使用LIKE运算符进行过滤,而不是严格相等。然而,这是行不通的:scope:my_scope,->(que
ruby如何管理内存。例如:如果我们在执行过程中采用C程序,则以下是内存模型。类似于这个ruby如何处理内存。C:__________________|||stack|||------------------||||------------------|||||Heap|||||__________________|||data|__________________|text|__________________Ruby:? 最佳答案 Ruby中没有“内存”这样的东西。Class#allocate分配一个对象并返回该对象。这就是程序
如何将send与+=一起使用?a=20;a.send"+=",10undefinedmethod`+='for20:Fixnuma=20;a+=10=>30 最佳答案 恐怕你不能。+=不是方法,而是语法糖。参见http://www.ruby-doc.org/docs/ProgrammingRuby/html/tut_expressions.html它说Incommonwithmanyotherlanguages,Rubyhasasyntacticshortcut:a=a+2maybewrittenasa+=2.你能做的最好的事情是:
我对如何计算通过{%assignvar=0%}赋值的变量加一完全感到困惑。这应该是最简单的任务。到目前为止,这是我尝试过的:{%assignamount=0%}{%forvariantinproduct.variants%}{%assignamount=amount+1%}{%endfor%}Amount:{{amount}}结果总是0。也许我忽略了一些明显的东西。也许有更好的方法。我想要存档的只是获取运行的迭代次数。 最佳答案 因为{{incrementamount}}将输出您的变量值并且不会影响{%assign%}定义的变量,我
我有一个.pfx格式的证书,我需要使用ruby提取公共(public)、私有(private)和CA证书。使用shell我可以这样做:#ExtractPublicKey(askforpassword)opensslpkcs12-infile.pfx-outfile_public.pem-clcerts-nokeys#ExtractCertificateAuthorityKey(askforpassword)opensslpkcs12-infile.pfx-outfile_ca.pem-cacerts-nokeys#ExtractPrivateKey(askforpassword)o