diff options
-rw-r--r-- | ChangeLog | 9 | ||||
-rw-r--r-- | Makefile.am | 2 | ||||
-rw-r--r-- | Makefile.in | 2 | ||||
-rw-r--r-- | auto_free.h | 28 | ||||
-rw-r--r-- | tapsets.cxx | 4 |
5 files changed, 36 insertions, 9 deletions
@@ -1,3 +1,12 @@ +2008-06-29 Tim Moore <timoore@redhat.com> + + * Makefile.am (EXTRA_DIST): Add auto_free.h. + * Makefile.in: Regenerated. + * auto_free.h (auto_free_ref): New class to free references to + pointers allocated with malloc / realloc. + * tapsets.cxx (iterate_over_srcfile_lines): Use auto_free_ref at + top level of function to free srcsp. + 2008-06-27 David Smith <dsmith@redhat.com> * tapsets.cxx (utrace_derived_probe_group::emit_module_decls): Fix diff --git a/Makefile.am b/Makefile.am index 3e5bd6c9..8333281e 100644 --- a/Makefile.am +++ b/Makefile.am @@ -148,7 +148,7 @@ endif # Get extra libs as needed LDADD = -EXTRA_DIST = buildrun.h elaborate.h loc2c.h session.h \ +EXTRA_DIST = auto_free.h buildrun.h elaborate.h loc2c.h session.h \ parse.h staptree.h tapsets.h translate.h \ cache.h hash.h mdfour.h util.h staplog.c coveragedb.h \ testsuite systemtap.spec runtime tapset \ diff --git a/Makefile.in b/Makefile.in index 675edde2..dc039c3f 100644 --- a/Makefile.in +++ b/Makefile.in @@ -324,7 +324,7 @@ loc2c_test_LDADD = $(stap_LDADD) # Get extra libs as needed LDADD = -EXTRA_DIST = buildrun.h elaborate.h loc2c.h session.h \ +EXTRA_DIST = auto_free.h buildrun.h elaborate.h loc2c.h session.h \ parse.h staptree.h tapsets.h translate.h \ cache.h hash.h mdfour.h util.h staplog.c coveragedb.h \ testsuite systemtap.spec runtime tapset \ diff --git a/auto_free.h b/auto_free.h index b13e7371..58290821 100644 --- a/auto_free.h +++ b/auto_free.h @@ -27,14 +27,32 @@ public: } private: // No copying allowed. - auto_free(const auto_free& af) + auto_free(const auto_free& af); + // No assignment either + auto_free& operator=(const auto_free& rhs); + void* _ptr; +}; + +// Use this to free a pointer whose value may change after the initial +// allocation e.g., be realloced. +template <typename T> +class auto_free_ref +{ +public: + typedef T pointer_type; + auto_free_ref(pointer_type& ptr) : _ptr(ptr) { } - // No assignment either - auto_free& operator=(const auto_free& rhs) + ~auto_free_ref() { - return *this; + if (_ptr) + std::free(_ptr); } - void* _ptr; +private: + // No copying allowed. + auto_free_ref(const auto_free_ref& af); + // No assignment either + auto_free_ref& operator=(const auto_free_ref& rhs); + pointer_type& _ptr; }; #endif diff --git a/tapsets.cxx b/tapsets.cxx index a405cef0..c054d24c 100644 --- a/tapsets.cxx +++ b/tapsets.cxx @@ -1184,7 +1184,8 @@ struct dwflpp size_t nsrcs = 0; dwarf_query * q = static_cast<dwarf_query *>(data); int lineno = lines[0]; - + auto_free_ref<Dwarf_Line**> free_srcsp(srcsp); + get_module_dwarf(); if (line_type == RELATIVE) @@ -1210,7 +1211,6 @@ struct dwflpp dwarf_getsrc_file (module_dwarf, srcfile, l, 0, &srcsp, &nsrcs)); - auto_free srcsp_af(srcsp); if (line_type == WILDCARD || line_type == RANGE) { Dwarf_Addr line_addr; |