Skip to content

Commit

Permalink
free glibc resources before analyzing leaks
Browse files Browse the repository at this point in the history
  • Loading branch information
d99kris committed Jan 22, 2022
1 parent fdcce86 commit 93c722b
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/heapusage
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ showusage()

showversion()
{
echo "heapusage v2.02"
echo "heapusage v2.03"
echo ""
echo "Copyright (C) 2017-2021 Kristofer Berggren"
echo ""
Expand Down
2 changes: 1 addition & 1 deletion src/heapusage.1
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
.\" DO NOT MODIFY THIS FILE! It was generated by help2man.
.TH HEAPUSAGE "1" "December 2021" "heapusage v2.02" "User Commands"
.TH HEAPUSAGE "1" "January 2022" "heapusage v2.03" "User Commands"
.SH NAME
heapusage \- find memory leaks in applications
.SH SYNOPSIS
Expand Down
15 changes: 15 additions & 0 deletions src/humain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
/* ----------- Includes ------------------------------------------ */
#include <atomic>
#include <cstdio>
#include <cstdlib>
#include <cstring>

#include <limits.h>
Expand Down Expand Up @@ -51,6 +52,14 @@ static pthread_mutex_t hu_recursive_lock = PTHREAD_RECURSIVE_MUTEX_INITIALIZER_N
#warning "unsupported platform"
#endif

#if defined(__GLIBC__)
extern "C" void __libc_freeres();
namespace __gnu_cxx
{
void __freeres();
}
#endif


/* ----------- Local Functions ----------------------------------- */
class hu_recursion_checker
Expand Down Expand Up @@ -118,6 +127,12 @@ void __attribute__ ((constructor)) hu_init(void)
extern "C"
void __attribute__ ((destructor)) hu_fini(void)
{
#if defined(__GLIBC__)
/* Free libc resources */
__libc_freeres();
__gnu_cxx::__freeres();
#endif

/* Disable logging */
log_enable(0);

Expand Down
2 changes: 1 addition & 1 deletion src/humalloc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ static int hu_mprotect(void* addr, size_t len, int prot)
if (callcount > (max_map_count / 2))
{
fprintf(stderr,
"max_map_count=%ld mprotect_count=%ld, try increasing max_map_count, ex::\n",
"max_map_count=%ld mprotect_count=%ld, try increasing max_map_count, ex:\n",
max_map_count, callcount);
fprintf(stderr, "sudo sh -c \"echo %ld > /proc/sys/vm/max_map_count\"\n",
(2 * max_map_count));
Expand Down

0 comments on commit 93c722b

Please sign in to comment.