summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrew Tridgell <tridge@samba.org>2004-10-11 05:23:46 +0000
committerGerald (Jerry) Carter <jerry@samba.org>2007-10-10 12:59:46 -0500
commit925251ea592bf7f341d2b4471cd5311fcabad109 (patch)
treefd1f0646dc3e6a0ffc976dd09abb0e4bfd3dcee0
parent38807f046bd94dc573922630cb49d247daa4c578 (diff)
downloadsamba-925251ea592bf7f341d2b4471cd5311fcabad109.tar.gz
samba-925251ea592bf7f341d2b4471cd5311fcabad109.tar.bz2
samba-925251ea592bf7f341d2b4471cd5311fcabad109.zip
r2907: auto destroy iconv memory handles on exit, to make valgrind leak
reports easier to read (less noisy) (This used to be commit e3009492b85ac90836aa9341687df5869f4ea291)
-rw-r--r--source4/lib/charcnv.c45
1 files changed, 26 insertions, 19 deletions
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