add memory check tool

This commit is contained in:
Sukchan Lee 2017-08-04 12:06:56 +09:00
parent 2e6f9f7a34
commit 9a91870324
10 changed files with 409 additions and 15 deletions

View File

@ -55,33 +55,29 @@ status_t proc_create(proc_id *id,
new->proc = getpid();
semaphore_post(new->sem1);
d_trace(3, "[%d] post semaphore for starting\n", new->proc);
d_trace(3, "start func wait\n");
d_trace(3, "core proc try to terminate\n");
rv = new->start_func((proc_id)new, new->data);
d_trace(3, "start func done(rv = %d)\n", rv);
d_trace(3, "start_func done(rv = %d)\n", rv);
d_trace(3, "deleting semaphore wait\n");
semaphore_wait(new->sem2);
d_trace(3, "deleting semaphore done\n");
d_trace(3, "received post from parent\n");
if (rv == CORE_OK)
{
d_trace(3, "stop func wait\n");
new->stop_func(new->proc, new->data);
d_trace(3, "stop func done\n");
d_trace(3, "stop_func done(rv = %d)\n", rv);
}
semaphore_post(new->sem1);
d_trace(3, "[%d] post semaphore to finish deleting\n", new->proc);
semaphore_delete(new->sem1);
semaphore_delete(new->sem2);
pool_free_node(&proc_pool, new);
d_trace(3, "delete proc-related memory\n");
d_trace(3, "delete core proc memory\n");
core_terminate();
d_trace(3, "core terminated in child process\n");
d_trace(3, "core proc terminate...done\n");
_exit(EXIT_SUCCESS);
}

View File

@ -22,7 +22,7 @@ AM_CPPFLAGS = \
-I$(top_srcdir)/lib/core/include
AM_CFLAGS = \
-Wall -Werror -DSYSCONFDIR=\"$(sysconfdir)/\"
-Wall -Werror
MAINTAINERCLEANFILES = Makefile.in
MOSTLYCLEANFILES = *.stackdump

View File

@ -4,17 +4,27 @@
#include "core_signal.h"
#include "core_semaphore.h"
#include "context.h"
#include "app.h"
status_t app_initialize(char *config_path, char *log_path)
{
status_t rv;
int others = 0;
rv = app_will_initialize(config_path, log_path);
if (rv != CORE_OK) return rv;
others = context_self()->trace_level.others;
if (others)
{
d_trace_level(&_hss_main, others);
}
d_trace(1, "HSS try to initialize\n");
rv = hss_initialize();
if (rv != CORE_OK) return rv;
d_assert(rv == CORE_OK, return rv, "Failed to intialize HSS");
d_trace(1, "HSS initialize...done\n");
rv = app_did_initialize(config_path, log_path);
if (rv != CORE_OK) return rv;
@ -26,7 +36,9 @@ void app_terminate(void)
{
app_will_terminate();
d_trace(1, "HSS try to terminate\n");
hss_terminate();
d_trace(1, "HSS terminate...done\n");
app_did_terminate();
}

View File

@ -34,6 +34,10 @@ status_t app_will_initialize(char *config_path, char *log_path)
if (others)
{
d_trace_level(&_app_init, others);
#if 0
extern int _proc;
d_trace_level(&_proc, 3);
#endif
}
if (log_path)

View File

@ -4,17 +4,27 @@
#include "core_signal.h"
#include "core_semaphore.h"
#include "context.h"
#include "app.h"
status_t app_initialize(char *config_path, char *log_path)
{
status_t rv;
int others = 0;
rv = app_will_initialize(config_path, log_path);
if (rv != CORE_OK) return rv;
others = context_self()->trace_level.others;
if (others)
{
d_trace_level(&_mme_main, others);
}
d_trace(1, "MME try to initialize\n");
rv = mme_initialize();
if (rv != CORE_OK) return rv;
d_assert(rv == CORE_OK, return rv, "Failed to intialize MME");
d_trace(1, "MME initialize...done\n");
rv = app_did_initialize(config_path, log_path);
if (rv != CORE_OK) return rv;
@ -26,7 +36,9 @@ void app_terminate(void)
{
app_will_terminate();
d_trace(1, "MME try to terminate\n");
mme_terminate();
d_trace(1, "MME terminate...done\n");
app_did_terminate();
}

View File

@ -4,17 +4,27 @@
#include "core_signal.h"
#include "core_semaphore.h"
#include "context.h"
#include "app.h"
status_t app_initialize(char *config_path, char *log_path)
{
status_t rv;
int others = 0;
rv = app_will_initialize(config_path, log_path);
if (rv != CORE_OK) return rv;
others = context_self()->trace_level.others;
if (others)
{
d_trace_level(&_pgw_main, others);
}
d_trace(1, "PGW try to initialize\n");
rv = pgw_initialize();
if (rv != CORE_OK) return rv;
d_assert(rv == CORE_OK, return rv, "Failed to intialize PGW");
d_trace(1, "PGW initialize...done\n");
rv = app_did_initialize(config_path, log_path);
if (rv != CORE_OK) return rv;
@ -26,7 +36,9 @@ void app_terminate(void)
{
app_will_terminate();
d_trace(1, "PGW try to terminate\n");
pgw_terminate();
d_trace(1, "PGW terminate...done\n");
app_did_terminate();
}

View File

@ -4,17 +4,27 @@
#include "core_signal.h"
#include "core_semaphore.h"
#include "context.h"
#include "app.h"
status_t app_initialize(char *config_path, char *log_path)
{
status_t rv;
int others = 0;
rv = app_will_initialize(config_path, log_path);
if (rv != CORE_OK) return rv;
others = context_self()->trace_level.others;
if (others)
{
d_trace_level(&_sgw_main, others);
}
d_trace(1, "SGW try to initialize\n");
rv = sgw_initialize();
if (rv != CORE_OK) return rv;
d_assert(rv == CORE_OK, return rv, "Failed to intialize SGW");
d_trace(1, "SGW initialize...done\n");
rv = app_did_initialize(config_path, log_path);
if (rv != CORE_OK) return rv;
@ -26,7 +36,9 @@ void app_terminate(void)
{
app_will_terminate();
d_trace(1, "SGW try to terminate\n");
sgw_terminate();
d_trace(1, "SGW terminate...done\n");
app_did_terminate();
}

View File

@ -0,0 +1,234 @@
{
<insert_a_suppression_name_here>
Memcheck:Leak
match-leak-kinds: reachable
fun:malloc
fun:strdup
fun:p11_kit_pin_register_callback
fun:gnutls_pkcs11_init
fun:gnutls_global_init
fun:fd_core_initialize
fun:s6a_fd_init
fun:s6a_init
fun:hss_s6a_init
fun:hss_initialize
fun:app_initialize
fun:main
}
{
<insert_a_suppression_name_here>
Memcheck:Leak
match-leak-kinds: reachable
fun:malloc
obj:/usr/lib/i386-linux-gnu/libgnutls.so.26.22.6
fun:gnutls_pkcs11_init
fun:gnutls_global_init
fun:fd_core_initialize
fun:s6a_fd_init
fun:s6a_init
fun:hss_s6a_init
fun:hss_initialize
fun:app_initialize
fun:main
}
{
<insert_a_suppression_name_here>
Memcheck:Leak
match-leak-kinds: reachable
fun:malloc
fun:strdup
fun:fd_log_threadname
fun:fd_core_initialize
fun:s6a_fd_init
fun:s6a_init
fun:hss_s6a_init
fun:hss_initialize
fun:app_initialize
fun:main
}
{
<insert_a_suppression_name_here>
Memcheck:Leak
match-leak-kinds: reachable
fun:calloc
fun:p11_kit_pin_register_callback
fun:gnutls_pkcs11_init
fun:gnutls_global_init
fun:fd_core_initialize
fun:s6a_fd_init
fun:s6a_init
fun:hss_s6a_init
fun:hss_initialize
fun:app_initialize
fun:main
}
{
<insert_a_suppression_name_here>
Memcheck:Leak
match-leak-kinds: reachable
fun:calloc
obj:/usr/lib/i386-linux-gnu/libp11-kit.so.0.0.0
fun:p11_kit_pin_register_callback
fun:gnutls_pkcs11_init
fun:gnutls_global_init
fun:fd_core_initialize
fun:s6a_fd_init
fun:s6a_init
fun:hss_s6a_init
fun:hss_initialize
fun:app_initialize
fun:main
}
{
<insert_a_suppression_name_here>
Memcheck:Leak
match-leak-kinds: reachable
fun:calloc
obj:/usr/lib/i386-linux-gnu/libp11-kit.so.0.0.0
obj:/usr/lib/i386-linux-gnu/libp11-kit.so.0.0.0
fun:p11_kit_pin_register_callback
fun:gnutls_pkcs11_init
fun:gnutls_global_init
fun:fd_core_initialize
fun:s6a_fd_init
fun:s6a_init
fun:hss_s6a_init
fun:hss_initialize
fun:app_initialize
}
{
<insert_a_suppression_name_here>
Memcheck:Leak
match-leak-kinds: reachable
fun:calloc
fun:_dlerror_run
fun:dlopen@@GLIBC_2.1
obj:/usr/lib/i386-linux-gnu/libp11-kit.so.0.0.0
obj:/usr/lib/i386-linux-gnu/libp11-kit.so.0.0.0
fun:p11_kit_initialize_registered
fun:gnutls_pkcs11_init
fun:gnutls_global_init
fun:fd_core_initialize
fun:s6a_fd_init
fun:s6a_init
fun:hss_s6a_init
}
{
<insert_a_suppression_name_here>
Memcheck:Leak
match-leak-kinds: reachable
fun:malloc
obj:/usr/lib/i386-linux-gnu/libgnutls.so.26.22.6
obj:/lib/i386-linux-gnu/libgcrypt.so.11.8.2
obj:/lib/i386-linux-gnu/libgcrypt.so.11.8.2
obj:/lib/i386-linux-gnu/libgcrypt.so.11.8.2
fun:gcry_check_version
obj:/usr/lib/i386-linux-gnu/libgnutls.so.26.22.6
fun:gnutls_global_init
fun:fd_core_initialize
fun:s6a_fd_init
fun:s6a_init
fun:hss_s6a_init
}
{
<insert_a_suppression_name_here>
Memcheck:Leak
match-leak-kinds: reachable
fun:malloc
obj:/usr/lib/i386-linux-gnu/libgnutls.so.26.22.6
obj:/lib/i386-linux-gnu/libgcrypt.so.11.8.2
obj:/lib/i386-linux-gnu/libgcrypt.so.11.8.2
obj:/lib/i386-linux-gnu/libgcrypt.so.11.8.2
obj:/lib/i386-linux-gnu/libgcrypt.so.11.8.2
obj:/lib/i386-linux-gnu/libgcrypt.so.11.8.2
fun:gcry_check_version
obj:/usr/lib/i386-linux-gnu/libgnutls.so.26.22.6
fun:gnutls_global_init
fun:fd_core_initialize
fun:s6a_fd_init
}
{
<insert_a_suppression_name_here>
Memcheck:Leak
match-leak-kinds: reachable
fun:malloc
obj:/usr/lib/i386-linux-gnu/libgnutls.so.26.22.6
obj:/lib/i386-linux-gnu/libgcrypt.so.11.8.2
obj:/lib/i386-linux-gnu/libgcrypt.so.11.8.2
obj:/lib/i386-linux-gnu/libgcrypt.so.11.8.2
obj:/lib/i386-linux-gnu/libgcrypt.so.11.8.2
fun:gcry_control
obj:/usr/lib/i386-linux-gnu/libgnutls.so.26.22.6
fun:gnutls_global_init
fun:fd_core_initialize
fun:s6a_fd_init
fun:s6a_init
}
{
<insert_a_suppression_name_here>
Memcheck:Leak
match-leak-kinds: reachable
fun:malloc
obj:/usr/lib/i386-linux-gnu/libp11-kit.so.0.0.0
fun:p11_kit_pin_register_callback
fun:gnutls_pkcs11_init
fun:gnutls_global_init
fun:fd_core_initialize
fun:s6a_fd_init
fun:s6a_init
fun:hss_s6a_init
fun:hss_initialize
fun:app_initialize
fun:main
}
{
<insert_a_suppression_name_here>
Memcheck:Leak
match-leak-kinds: reachable
fun:malloc
fun:realloc
obj:/usr/lib/i386-linux-gnu/libp11-kit.so.0.0.0
obj:/usr/lib/i386-linux-gnu/libp11-kit.so.0.0.0
fun:p11_kit_pin_register_callback
fun:gnutls_pkcs11_init
fun:gnutls_global_init
fun:fd_core_initialize
fun:s6a_fd_init
fun:s6a_init
fun:hss_s6a_init
fun:hss_initialize
}
{
<insert_a_suppression_name_here>
Memcheck:Leak
match-leak-kinds: reachable
fun:malloc
obj:/lib/i386-linux-gnu/libgcrypt.so.11.8.2
obj:/lib/i386-linux-gnu/libgcrypt.so.11.8.2
obj:/lib/i386-linux-gnu/libgcrypt.so.11.8.2
obj:/lib/i386-linux-gnu/libgcrypt.so.11.8.2
obj:/lib/i386-linux-gnu/libgcrypt.so.11.8.2
obj:/lib/i386-linux-gnu/libgcrypt.so.11.8.2
obj:/lib/i386-linux-gnu/libgcrypt.so.11.8.2
obj:/lib/i386-linux-gnu/libgcrypt.so.11.8.2
fun:gcry_check_version
obj:/usr/lib/i386-linux-gnu/libgnutls.so.26.22.6
fun:gnutls_global_init
}
{
<insert_a_suppression_name_here>
Memcheck:Leak
match-leak-kinds: reachable
fun:malloc
obj:/lib/i386-linux-gnu/libgcrypt.so.11.8.2
obj:/lib/i386-linux-gnu/libgcrypt.so.11.8.2
obj:/lib/i386-linux-gnu/libgcrypt.so.11.8.2
obj:/lib/i386-linux-gnu/libgcrypt.so.11.8.2
obj:/lib/i386-linux-gnu/libgcrypt.so.11.8.2
obj:/lib/i386-linux-gnu/libgcrypt.so.11.8.2
obj:/lib/i386-linux-gnu/libgcrypt.so.11.8.2
fun:gcry_create_nonce
obj:/usr/lib/i386-linux-gnu/libgnutls.so.26.22.6
obj:/usr/lib/i386-linux-gnu/libgnutls.so.26.22.6
fun:gnutls_global_init
}

View File

@ -0,0 +1,55 @@
{
ignore_libcrypto_conditional_jump_errors_in_leak
Memcheck:Leak
...
obj:*/libcrypto.so.*
}
{
ignore_libcrypto_conditional_jump_errors_in_cond
Memcheck:Cond
...
obj:*/libcrypto.so.*
}
{
ignore_libssl_conditional_jump_errors_in_cond
Memcheck:Cond
...
obj:*/libssl.so.*
}
{
ignore_libcrypto_conditional_jump_errors_in_value8
Memcheck:Value8
...
obj:*/libcrypto.so.*
}
{
ignore_scram_nonce_uninitialized_warning_cond
Memcheck:Cond
fun:mongoc_b64_ntop
...
fun:_mongoc_scram_step
...
}
{
ignore_scram_nonce_uninitialized_warning_value8
Memcheck:Value8
fun:mongoc_b64_ntop
...
fun:_mongoc_scram_step
...
}
{
ignore_libcrypto_conditional_jump_errors_in_param
Memcheck:Param
sendmsg(msg.msg_iov[0])
...
obj:*/libcrypto.so.*
}
{
ignore_sasl_load_plugin_reachable_warnings
Memcheck:Leak
...
fun:_sasl_get_plugin
...
fun:_mongoc_do_init
}

View File

@ -0,0 +1,57 @@
#! /usr/bin/awk -f
# A script to extract the actual suppression info from the output of (for example) valgrind --leak-check=full --show-reachable=yes --error-limit=no --gen-suppressions=all ./minimal
# The desired bits are between ^{ and ^} (including the braces themselves).
# The combined output should either be appended to /usr/lib/valgrind/default.supp, or placed in a .supp of its own
# If the latter, either tell valgrind about it each time with --suppressions=<filename>, or add that line to ~/.valgrindrc
# NB This script uses the |& operator, which I believe is gawk-specific. In case of failure, check that you're using gawk rather than some other awk
# The script looks for suppressions. When it finds one it stores it temporarily in an array,
# and also feeds it line by line to the external app 'md5sum' which generates a unique checksum for it.
# The checksum is used as an index in a different array. If an item with that index already exists the suppression must be a duplicate and is discarded.
BEGIN { suppression=0; md5sum = "md5sum" }
# If the line begins with '{', it's the start of a supression; so set the var and initialise things
/^{/ {
suppression=1; i=0; next
}
# If the line begins with '}' its the end of a suppression
/^}/ {
if (suppression)
{ suppression=0;
close(md5sum, "to") # We've finished sending data to md5sum, so close that part of the pipe
ProcessInput() # Do the slightly-complicated stuff in functions
delete supparray # We don't want subsequent suppressions to append to it!
}
}
# Otherwise, it's a normal line. If we're inside a supression, store it, and pipe it to md5sum. Otherwise it's cruft, so ignore it
{ if (suppression)
{
supparray[++i] = $0
print |& md5sum
}
}
function ProcessInput()
{
# Pipe the result from md5sum, then close it
md5sum |& getline result
close(md5sum)
# gawk can't cope with enormous ints like $result would be, so stringify it first by prefixing a definite string
resultstring = "prefix"result
if (! (resultstring in chksum_array) )
{ chksum_array[resultstring] = 0; # This checksum hasn't been seen before, so add it to the array
OutputSuppression() # and output the contents of the suppression
}
}
function OutputSuppression()
{
# A suppression is surrounded by '{' and '}'. Its data was stored line by line in the array
print "{"
for (n=1; n <= i; ++n)
{ print supparray[n] }
print "}"
}