From 46bcfad42774d1a331ff7b4375696a859cc55c51 Mon Sep 17 00:00:00 2001 From: Nikolai Nosov Date: Thu, 23 Apr 2020 09:22:20 +0400 Subject: [PATCH] small refactoring. memory leak fix --- src/dwarf/dwarf_function.c | 2 +- src/dwarf/dwarf_handler.c | 4 ++-- src/dwarf/dwarf_handler.h | 2 +- src/libpst.c | 5 ++++- 4 files changed, 8 insertions(+), 5 deletions(-) diff --git a/src/dwarf/dwarf_function.c b/src/dwarf/dwarf_function.c index e3cf4f0..4099c17 100644 --- a/src/dwarf/dwarf_function.c +++ b/src/dwarf/dwarf_function.c @@ -472,7 +472,7 @@ void pst_function_fini(pst_function* fn) clear(fn); if(fn->frame) { - // use free here because it was allocate out of our control by libdw + // use free here because it was allocated out of our control by libdw free(fn->frame); } diff --git a/src/dwarf/dwarf_handler.c b/src/dwarf/dwarf_handler.c index f5b5169..c2cbbb9 100644 --- a/src/dwarf/dwarf_handler.c +++ b/src/dwarf/dwarf_handler.c @@ -135,7 +135,7 @@ static pst_function* last_function(pst_handler* h) bool pst_handler_handle_dwarf(pst_handler* h) { if(!h->functions.count) { - if(!pst_handler_unwind(h)) { + if(!pst_handler_unwind_simple(h)) { return false; } } @@ -200,7 +200,7 @@ const char* pst_print_simple(pst_handler* h) } -bool pst_handler_unwind(pst_handler* h) +bool pst_handler_unwind_simple(pst_handler* h) { void* caller = NULL; // pointer to the function which requested to unwind stack diff --git a/src/dwarf/dwarf_handler.h b/src/dwarf/dwarf_handler.h index 8a4dc0b..62a5d4b 100644 --- a/src/dwarf/dwarf_handler.h +++ b/src/dwarf/dwarf_handler.h @@ -27,7 +27,7 @@ pst_handler* pst_handler_new(ucontext_t* hctx); void pst_handler_fini(pst_handler* h); bool pst_handler_handle_dwarf(pst_handler* h); -bool pst_handler_unwind(pst_handler* h); +bool pst_handler_unwind_simple(pst_handler* h); pst_function* pst_handler_next_function(pst_handler* h, pst_function* fn); #endif /* __PST_DWARF_HANDLER_H__ */ diff --git a/src/libpst.c b/src/libpst.c index 94b51af..7747c40 100644 --- a/src/libpst.c +++ b/src/libpst.c @@ -22,15 +22,18 @@ pst_handler* pst_lib_init(ucontext_t* hctx, void* buff, uint32_t size) } else { pst_alloc_init_custom(&allocator, buff, size); } + pst_log_init_console(&logger); pst_new(pst_handler, handler, hctx); + return handler; } // deallocate libpst handler and library void pst_lib_fini(pst_handler* h) { + pst_handler_fini(h); pst_free(h); // global @@ -41,7 +44,7 @@ void pst_lib_fini(pst_handler* h) // save stack trace information to provided buffer in RAM int pst_unwind_simple(pst_handler* h) { - return pst_handler_unwind(h); + return pst_handler_unwind_simple(h); } // save stack trace information to provided buffer in RAM