small refactoring. memory leak fix

This commit is contained in:
2020-04-23 09:22:20 +04:00
parent e18fdd78a1
commit 46bcfad427
4 changed files with 8 additions and 5 deletions
+1 -1
View File
@@ -472,7 +472,7 @@ void pst_function_fini(pst_function* fn)
clear(fn); clear(fn);
if(fn->frame) { 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); free(fn->frame);
} }
+2 -2
View File
@@ -135,7 +135,7 @@ static pst_function* last_function(pst_handler* h)
bool pst_handler_handle_dwarf(pst_handler* h) bool pst_handler_handle_dwarf(pst_handler* h)
{ {
if(!h->functions.count) { if(!h->functions.count) {
if(!pst_handler_unwind(h)) { if(!pst_handler_unwind_simple(h)) {
return false; 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 void* caller = NULL; // pointer to the function which requested to unwind stack
+1 -1
View File
@@ -27,7 +27,7 @@ pst_handler* pst_handler_new(ucontext_t* hctx);
void pst_handler_fini(pst_handler* h); void pst_handler_fini(pst_handler* h);
bool pst_handler_handle_dwarf(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); pst_function* pst_handler_next_function(pst_handler* h, pst_function* fn);
#endif /* __PST_DWARF_HANDLER_H__ */ #endif /* __PST_DWARF_HANDLER_H__ */
+4 -1
View File
@@ -22,15 +22,18 @@ pst_handler* pst_lib_init(ucontext_t* hctx, void* buff, uint32_t size)
} else { } else {
pst_alloc_init_custom(&allocator, buff, size); pst_alloc_init_custom(&allocator, buff, size);
} }
pst_log_init_console(&logger); pst_log_init_console(&logger);
pst_new(pst_handler, handler, hctx); pst_new(pst_handler, handler, hctx);
return handler; return handler;
} }
// deallocate libpst handler and library // deallocate libpst handler and library
void pst_lib_fini(pst_handler* h) void pst_lib_fini(pst_handler* h)
{ {
pst_handler_fini(h);
pst_free(h); pst_free(h);
// global // global
@@ -41,7 +44,7 @@ void pst_lib_fini(pst_handler* h)
// save stack trace information to provided buffer in RAM // save stack trace information to provided buffer in RAM
int pst_unwind_simple(pst_handler* h) 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 // save stack trace information to provided buffer in RAM