From 925251ea592bf7f341d2b4471cd5311fcabad109 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Mon, 11 Oct 2004 05:23:46 +0000 Subject: r2907: auto destroy iconv memory handles on exit, to make valgrind leak reports easier to read (less noisy) (This used to be commit e3009492b85ac90836aa9341687df5869f4ea291) --- source4/lib/charcnv.c | 45 ++++++++++++++++++++++++++------------------- 1 file changed, 26 insertions(+), 19 deletions(-) (limited to 'source4/lib') diff --git a/source4/lib/charcnv.c b/source4/lib/charcnv.c index e5331b973e..10063c9f3c 100644 --- a/source4/lib/charcnv.c +++ b/source4/lib/charcnv.c @@ -57,25 +57,6 @@ static const char *charset_name(charset_t ch) static smb_iconv_t conv_handles[NUM_CHARSETS][NUM_CHARSETS]; -/* - on-demand initialisation of conversion handles -*/ -static smb_iconv_t get_conv_handle(charset_t from, charset_t to) -{ - const char *n1, *n2; - - if (conv_handles[from][to]) { - return conv_handles[from][to]; - } - - n1 = charset_name(from); - n2 = charset_name(to); - - conv_handles[from][to] = smb_iconv_open(n2,n1); - - return conv_handles[from][to]; -} - /** re-initialize iconv conversion descriptors **/ @@ -95,6 +76,32 @@ void init_iconv(void) } +/* + on-demand initialisation of conversion handles +*/ +static smb_iconv_t get_conv_handle(charset_t from, charset_t to) +{ + const char *n1, *n2; + static int initialised; + /* auto-free iconv memory on exit so valgrind reports are easier + to look at */ + if (initialised == 0) { + initialised = 1; + atexit(init_iconv); + } + + if (conv_handles[from][to]) { + return conv_handles[from][to]; + } + + n1 = charset_name(from); + n2 = charset_name(to); + + conv_handles[from][to] = smb_iconv_open(n2,n1); + + return conv_handles[from][to]; +} + /** * Convert string from one encoding to another, making error checking etc -- cgit