Hi, There was indeed a stupid memory leak in pfm_perf_event_encode(). I just fixed it, so please pull again from the git repository.
Thanks for reporting the issue. On Tue, Aug 16, 2011 at 3:35 PM, Leonardo Piga <leonardo.p...@gmail.com> wrote: > > I'm using the following code to create the events in C++. Everything > is working, but valgrind is reporting memory leak on line 08. > > I suppose that the library is allocating some memory on arg structure > that needs to be freed. What should I free? > > > string name; > bool started; > pfm_perf_encode_arg_t arg; > > perf_event_attr hw; > int fd; > > > > 01 int ret; > 02 memset(&arg, 0, sizeof(arg)); > 03 memset(&hw, 0, sizeof(hw)); > 04 arg.attr = &hw; > 05 > 06 started = false; > 07 prevValue = value = 0; > 08 ret = pfm_get_os_event_encoding(name.c_str(), > PFM_PLM0|PFM_PLM3|PFM_PLMH, PFM_OS_PERF_EVENT_EXT, &arg); > 09 if (ret != PFM_SUCCESS) { > 10 stringstream msgStr; > 11 msgStr << "event " << name << ": " << pfm_strerror(ret) << endl; > 12 throw msgStr.str(); > 13 } > 14 > 15 // ABI compatibility > 16 hw.size = sizeof(struct perf_event_attr); > 17 > 18 // Setup steps > 19 fd = -1; > 20 hw.disabled = 1; > 21 hw.read_format = PERF_FORMAT_SCALE; > 22 fd = perf_event_open(&hw, -1, cpu, -1, 0); > 23 if (fd == - 1) { > 24 stringstream msgStr; > 25 msgStr << "cannot attach event to CPU" << cpu << " " << name << endl; > 26 throw msgStr.str(); > 27 } > > Here is the valgind output: > ==3482== 576 bytes in 2 blocks are definitely lost in loss record 1 of 1 > ==3482== at 0x4025230: malloc (vg_replace_malloc.c:236) > ==3482== by 0x407BB3E: pfmlib_build_event_pattrs (pfmlib_common.c:794) > ==3482== by 0x407C0BB: pfmlib_parse_event (pfmlib_common.c:972) > ==3482== by 0x407FA72: pfmlib_perf_event_encode (pfmlib_perf_event.c:90) > ==3482== by 0x407C34C: pfm_get_os_event_encoding (pfmlib_common.c:1108) > ==3482== by 0x804E5BA: Event::Event(int, std::string const&) (Event.cpp:64) > ... > ==3482== LEAK SUMMARY: > ==3482== definitely lost: 576 bytes in 2 blocks > ==3482== indirectly lost: 0 bytes in 0 blocks > ==3482== possibly lost: 0 bytes in 0 blocks > ==3482== still reachable: 0 bytes in 0 blocks > ==3482== suppressed: 0 bytes in 0 blocks > > > > > Thank you > -- > Leonardo > > ------------------------------------------------------------------------------ > uberSVN's rich system and user administration capabilities and model > configuration take the hassle out of deploying and managing Subversion and > the tools developers use with it. Learn more about uberSVN and get a free > download at: http://p.sf.net/sfu/wandisco-dev2dev > _______________________________________________ > perfmon2-devel mailing list > perfmon2-devel@lists.sourceforge.net > https://lists.sourceforge.net/lists/listinfo/perfmon2-devel ------------------------------------------------------------------------------ uberSVN's rich system and user administration capabilities and model configuration take the hassle out of deploying and managing Subversion and the tools developers use with it. Learn more about uberSVN and get a free download at: http://p.sf.net/sfu/wandisco-dev2dev _______________________________________________ perfmon2-devel mailing list perfmon2-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/perfmon2-devel