improve talloc memory leak debugging

* switch to talloc_report_full() on SIGUSR1
* include asn1-internal allocations in talloc report

Change-Id: I14fff863449971024002e0d5465fb7a964d67095
This commit is contained in:
Harald Welte 2019-03-31 15:57:59 +02:00
parent 3f09f634e0
commit b54a51eec2
5 changed files with 16 additions and 9 deletions

View File

@ -23,10 +23,12 @@ extern "C" {
#define ASN1C_ENVIRONMENT_VERSION 924 /* Compile-time version */
int get_asn1c_environment_version(void); /* Run-time version */
#define CALLOC(nmemb, size) calloc(nmemb, size)
#define MALLOC(size) malloc(size)
#define REALLOC(oldptr, size) realloc(oldptr, size)
#define FREEMEM(ptr) free(ptr)
#include <osmocom/core/talloc.h>
extern __thread void *talloc_asn1_ctx;
#define CALLOC(nmemb, size) talloc_zero_size(talloc_asn1_ctx, (nmemb) * (size))
#define MALLOC(size) talloc_size(talloc_asn1_ctx, size)
#define REALLOC(oldptr, size) talloc_realloc_size(talloc_asn1_ctx, oldptr, size)
#define FREEMEM(ptr) talloc_free(ptr)
#define asn_debug_indent 0
#define ASN_DEBUG_INDENT_ADD(i) do{}while(0)

View File

@ -330,7 +330,7 @@ static void handle_sig_usr1(int sig)
struct bankd_worker *worker;
/* main thread */
fprintf(stderr, "=== Talloc Report of main thread:\n");
talloc_report(g_tall_ctx, stderr);
talloc_report_full(g_tall_ctx, stderr);
/* iterate over worker threads and ask them to dump their talloc state */
pthread_mutex_lock(&g_bankd->workers_mutex);
@ -341,7 +341,7 @@ static void handle_sig_usr1(int sig)
} else {
/* worker thread */
fprintf(stderr, "=== Talloc Report of %s\n", g_worker->name);
talloc_report(g_worker->tall_ctx, stderr);
talloc_report_full(g_worker->tall_ctx, stderr);
}
}

View File

@ -164,7 +164,7 @@ static int srvc_handle_rx(struct rspro_server_conn *srvc, const RsproPDU_t *pdu)
static void handle_sig_usr1(int signal)
{
OSMO_ASSERT(signal == SIGUSR1);
talloc_report(g_tall_ctx, stderr);
talloc_report_full(g_tall_ctx, stderr);
}
static void printf_help()
@ -229,6 +229,7 @@ int main(int argc, char **argv)
int rc;
g_tall_ctx = talloc_named_const(NULL, 0, "global");
talloc_asn1_ctx = talloc_named_const(g_tall_ctx, 0, "asn1");
osmo_init_logging2(g_tall_ctx, &log_info);

View File

@ -15,12 +15,14 @@
struct rspro_server *g_rps;
void *g_tall_ctx;
__thread void *talloc_asn1_ctx;
struct osmo_fd g_event_ofd;
static void handle_sig_usr1(int signal)
{
OSMO_ASSERT(signal == SIGUSR1);
talloc_report(g_tall_ctx, stderr);
talloc_report_full(g_tall_ctx, stderr);
}
int main(int argc, char **argv)
@ -28,6 +30,7 @@ int main(int argc, char **argv)
int rc;
g_tall_ctx = talloc_named_const(NULL, 0, "global");
talloc_asn1_ctx = talloc_named_const(g_tall_ctx, 0, "asn1");
osmo_init_logging2(g_tall_ctx, &log_info);

View File

@ -679,7 +679,7 @@ static int srvc_handle_rx(struct rspro_server_conn *srvc, const RsproPDU_t *pdu)
static void handle_sig_usr1(int signal)
{
OSMO_ASSERT(signal == SIGUSR1);
talloc_report(g_tall_ctx, stderr);
talloc_report_full(g_tall_ctx, stderr);
}
static void print_welcome(void)
@ -817,6 +817,7 @@ int main(int argc, char **argv)
signal(SIGUSR1, handle_sig_usr1);
g_tall_ctx = talloc_named_const(NULL, 0, "global");
talloc_asn1_ctx = talloc_named_const(g_tall_ctx, 0, "asn1");
osmo_init_logging2(g_tall_ctx, &log_info);
rc = libusb_init(NULL);